カスタムセルの作り方
xibファイルを作る
New File > User Interface > Empty
で空のxibファイルを作る。
Table View Cellを配置
xibに Table View Cell をドラッグアンドドロップで配置
セルに要素を配置
セルにImage Viewなどをドラッグアンドドロップで配置
File's Ownerを変更
File's Ownerがどこにもひもづいていないので、
カスタムセルを使いたいクラスを設定
File's Ownerでカスタムセルを使ったプログラミング
カスタムセルをIBOutletでひも付け。
IBOutlet UITableViewCell *cell;
カスタムセルを読み込む(リサイクルしない場合)
- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { [[NSBundle mainBundle] loadNibNamed:@"カスタムセルのxib名" owner:self options:nil]; UITableViewCell *cell = [[self.cell retain] autorelease]; // なぜか self.cellに読み込まれている まあ不思議 return cell; }
セルの高さを指定
セルの高さは自動で設定してくれないので、
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
で実装。
配置した要素に値を書き込む
((UIImageView *)[cell viewWithTag:3]).image = // なんか値
みたいにタグでアクセスするのが楽。