私は、一般的な問題であると確信しているものを解決しようとしています。
ストーリーボードに接続された UITableViewController があり、2 つのプロトタイプ セルを使用しています。ナビゲーション コントローラーの最初のビューでは、すべてのセルが正しく読み込まれます。私の問題は、その UITableViewController の別のインスタンスをナビゲーション スタックにプッシュしようとしたときに発生します (データは異なります)。
再利用が識別されたセルはストーリーボードの最初のビューにのみ関連付けられており、必ずしもクラス自体には関連付けられていないため、これらのプロトタイプ セルを再利用しnil
て から予測可能な応答を取得する機能が失われていdequeueReusableCellWithIdentifier:
ます。
スタックの後半でプロトタイプ セルの使用を維持するにはどうすればよいですか? カスタムセルを含むペン先を接続し、それをテーブルビューに入力する唯一の解決策はありますか?
私の表示ロジックは以下の通りです。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
id toDisplay = [[navPool getObjectsForParent:indexPath.section] objectAtIndex:indexPath.row];
if ([toDisplay isKindOfClass:[Category class]]) {
Category *currentCategory = toDisplay;
static NSString *CellIdentifier = @"Category";
CategoryCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = currentCategory.name;
[cell setCategoryId:currentCategory.categoryId];
return cell;
} else {
if ([toDisplay isKindOfClass:[ListTopic class]]) {
ListTopic *currentTopic = toDisplay;
static NSString *CellIdentifier = @"Topic";
ListTopicCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = currentTopic.name;
return cell;
}
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if ([cell isKindOfClass:[CategoryCell class]]) {
CategoryCell *cell = (CategoryCell *)[self.tableView cellForRowAtIndexPath:indexPath];
BrowseViewController *newView = [[BrowseViewController alloc] initWithStyle:UITableViewStylePlain andParent:[cell.categoryId intValue]];
[self.navigationController pushViewController:newView animated:YES];
} else if ([cell isKindOfClass:[ListTopicCell class]]) {
// push detail view
}
}