tableView:cellForRowAtIndexPath: 内からカスタム テーブル セルを処理する方法に非常に興味があります。
viewDidLoad でカスタム テーブル セルをインスタンス化します。私の質問は、再利用可能なセルがない場合に cellForRowAtIndexPath の状況をどのように処理するかです。たとえば、検索結果を返すとき。必要な場合、新しいカスタム セルを作成するにはどうすればよいですか? 以下に関連するメソッドを含めました。
ありがとう
-(void)viewDidLoad
{
[super viewDidLoad];
//Load custom table cell
UINib *customCellNib = [UINib nibWithNibName:@"CustomItem" bundle:nil];
//Register this nib, which contains the cell
[[self tableView] registerNib:customCellNib forCellReuseIdentifier:@"CustomItemCell"];
//.... More stuff here
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomItemCell *cell =
[tableView dequeueReusableCellWithIdentifier:@"CustomItemCell"];
// If there is no reusable cell of this type, create a new one
if (!cell) {
//Is this right?
cell = [[CustomItemCell alloc] init];
}
//Set up cell with data here...
return cell;
}