テーブルビューセルをInterfaceBuilderで作る場合の注意
はじめてのiPhone3プログラミング に複雑なテーブルビューのセル(UITableViewCell)をnterfaceBuilderで作る方法が書かれています。
要約すると
- UITableViewCellを継承したカスタム・テーブルビューセルクラスを作る
- カスタム・テーブルビューセルクラス上でプログラムと関連するUI要素をメンバーにする
- InterfaceBuilderでカスタム・テーブルビューセル用のxibをデザインする
- InterfaceBuilderで1で作ったメンバーとUIの対応付けを行う
- プログラムでは NIBからテーブルビューセルを読み込む
// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CouponTableViewCellIdentifier"; CouponTableViewCell *cell = (CouponTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CouponTableViewCell" owner:self options:nil]; for (id obj in nib) { if ([obj isKindOfClass:[CouponTableViewCell class]]) { cell = (CouponTableViewCell *)obj; } } } ・・・・
ここで注意しなければいけないのが、3のUIとメンバーの対応付けですが、File'sOwnerでは無く、スタム・テーブルビューセルと対応付けするという点です。
私はここでハマリました ^^);