[iphone] IB 를 이용해서 Custom TableViewCell 만들기
일단 UITableViewCell Class를 하나 만들고 Empty Xib 파일도 만든다.
일단 뷰에 UITableViewCell을 추가하고
그뒤 저렇게 Files'Owner에서 class를 UIViewController로 바꾼다.
이번에는 UITableViewCell에 가서
이렇게 바꾸고
identifer도 바꾼다. 바꾸면 이렇게 된다.
자 이제 클래스 파일을 수정하자
헤더파일이다
#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];
실제 사용하는부분에 이렇게 사용했다 ,