- http://konton.ninpou.jp/program/cocoa/userinterface/UITableView/UITableView1.html
- http://d.hatena.ne.jp/KishikawaKatsumi/20081024/1224857278
- http://ameblo.jp/xcc/entry-10503210925.html
を参考に。今日始めてiPhoneアプリを開発を始めたばかりの素人なので、Interface Builderの使い方にイマイチ慣れていなくて時間をかけてしまった……
CustomCell.h
@interface CustomCell : UITableViewCell { UILabel *titleLabel; UILabel *textLabel; UIImageView *image; } @property (nonatomic, retain) IBOutlet UILabel *titleLabel; @property (nonatomic, retain) IBOutlet UILabel *textLabel; @property (nonatomic, retain) IBOutlet UIImageView *image;
CustomCell.m
@implementation CustomCell @synthesize titleLabel; @synthesize textLabel; @synthesize image; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { // Initialization code } return self; } - (void)dealloc { [titleLabel release]; [textLabel release]; [image release]; [super dealloc]; }
CustomControll.h
#import "CustomCell.h" @interface CustomCellController : UIViewController { IBOutlet CustomCell* cell; } @property (nonatomic, retain) CustomCell* cell;
TableAppDelegate.m
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath { // セルを作る CustomCell *cell; cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:@"CustomCell"]; if (cell == nil) { CustomCellController *controller = [[CustomCellController alloc] initWithNibName:@"CustomCell" bundle:nil]; cell = (CustomCell *)controller.view; [controller release]; } // 適当な文章を表示する [cell.titleLabel setText:@"タイトル"]; [cell.textLabel setText:@"テキストテキストテキストテキスト"]; return cell; }