UITableView で実際に問題が発生しました。順を追って説明します。
ストーリーボードに UITableViewController があり、それぞれに独自の識別子を持つ 4 つの異なるプロトタイプ セルがあります。
次に、コントローラーのクラスにこれがあります。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"name";
if (indexPath.section == 0) CellIdentifier = @"name";
else if (indexPath.section == 1) CellIdentifier = @"name";
else if (indexPath.section == 2 && indexPath.row == 0) CellIdentifier = @"segment";
else if (indexPath.section == 2 && (indexPath.row == 1 || indexPath.row == 2 || indexPath.row == 3)) CellIdentifier = @"switch";
else if (indexPath.section == 3) CellIdentifier = @"segment";
else if (indexPath.section == 4) CellIdentifier = @"segment2";
else if (indexPath.section == 5) CellIdentifier = @"name";
else if (indexPath.section == 6) CellIdentifier = @"name";
else if (indexPath.section == 7) CellIdentifier = @"name";
GuestDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[GuestDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//Configure my cells here, like so:
if (indexPath.section == 0)
{
cell.title.text = @"title";
}
else if (indexPath.section == 1)
{
}
//etc
return cell;
}
私はいくつかの異なるコードで成功したので、これが私の問題があると思います(あなたがそれを見る必要がある場合は追加します、私に知らせてください.
正しい数のセルがテーブルに表示され、正しい数のセクションが表示されます。セルを選択すると、正しいサブビューコントローラーに移動しますが、実際のセル自体は空白です。なぜそれらはすべて nil を返すのでしょうか?
ビューが表示されると、すべてのセルが空白になります。cell = [[GuestDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
これは、構成された表示としてのセルとは対照的に、何度も呼び出されているようです。
このコードを呼び出すことで、このビューに到達します。
- (void)addNewGuest
{
newGuestViewController *addGuestViewController = [[newGuestViewController alloc] initWithStyle:UITableViewStylePlain];
addGuestViewController.delegate = self;
//Create a new managed object context for the new guest -- set its persistent store coordinator to the same as that from the fetched results controller's context.
NSManagedObjectContext *addingContext = [[NSManagedObjectContext alloc] init];
self.addingManagedObjectContext = addingContext;
[addingManagedObjectContext setPersistentStoreCoordinator:[[fetchedResultsController managedObjectContext] persistentStoreCoordinator]];
addGuestViewController.guest = (GuestInfo *)[NSEntityDescription insertNewObjectForEntityForName:@"GuestInfo" inManagedObjectContext:addingContext];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addGuestViewController];
[self.navigationController presentModalViewController:navController animated:YES];
}
何かアイデアがありますか、それとももっと情報が必要ですか?
ありがとう。