'IB'에 해당되는 글 1건

  1. 2011.07.27 [iphone] IB 를 이용해서 Custom TableViewCell 만들기
iPhone App2011. 7. 27. 17:18

일단 UITableViewCell Class를 하나 만들고 Empty Xib 파일도 만든다.

201107271711.jpg

일단 뷰에 UITableViewCell을 추가하고

그뒤 저렇게 Files'Owner에서 class를 UIViewController로 바꾼다.

이번에는 UITableViewCell에 가서


201107271715.jpg

이렇게 바꾸고


201107271716.jpg

identifer도 바꾼다. 바꾸면 이렇게 된다.


201107271716.jpg

자 이제 클래스 파일을 수정하자

헤더파일이다

#import <UIKit/UIKit.h>


#define HugeBoardCellIdentifier @"HugeBoardCellIdentifier"


@interface HugeBoardCell : UITableViewCell {

IBOutlet UILabel *titleLabel;

IBOutlet UILabel *idxLabel;

}


@property (nonatomic,retain) IBOutlet UILabel *titleLabel;

@property (nonatomic,retain) IBOutlet UILabel *idxLabel;

+ (id)cellWithNib;


@end


딴건 중요하지 않고 cellWithNib이 중요하다
실제 구현부에

+ (id)cellWithNib

{

HugeBoardCell *cell;

UIViewController *controller = [[UIViewController alloc] initWithNibName:@"HugeBoardCell" bundle:nil];

cell = (HugeBoardCell *)controller.view;

[controller release];

return cell;

}


이렇게 추가한다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

  HugeBoardCell *cell = (HugeBoardCell *)[tableView dequeueReusableCellWithIdentifier:HugeBoardCellIdentifier];

  

if (cell == nil) {   

cell = [HugeBoardCell cellWithNib];   

}

HugeBoardData* hd = [boardData objectAtIndex:indexPath.row];

cell.titleLabel.text = [NSString stringWithFormat:@"%@", hd.title];

cell.idxLabel.text= [NSString stringWithFormat:@"%@ : ", hd.idx];


실제 사용하는부분에 이렇게 사용했다 ,
Posted by 동동(이재동)