Iphone UITableView单元格为空

Iphone UITableView单元格为空,iphone,objective-c,ipad,uitableview,Iphone,Objective C,Ipad,Uitableview,我对我的UITableView有一个真正的问题,让我带你看看 我的故事板中有一个UITableViewController,它有四个不同的原型单元,每个单元都有自己的标识符 然后我在课堂上为控制器准备了这个: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"

我对我的UITableView有一个真正的问题,让我带你看看

我的故事板中有一个UITableViewController,它有四个不同的原型单元,每个单元都有自己的标识符

然后我在课堂上为控制器准备了这个:

- (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;
}
我想这就是我的问题所在,因为我已经成功地使用了一些不同的代码(如果您可能需要查看,请告诉我,我将添加这些代码)

表格中显示的单元格数量正确,分区数量正确,如果您选择一个单元格,它会将您带到右侧的子viewcontroller,但实际的单元格本身只是空白。为什么它们都会返回零

现在,当视图显示时,所有单元格都是空白的。
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];
}
有什么想法,或者需要更多信息吗


谢谢。

这让我抓狂。当着客户的面把我难住了。jrturton的评论得到了我需要的答案。由于没有任何答案,这个问题一开始就被忽略了。将jrturton的评论作为答案发布,这样就不太可能被忽视。以下是他的评论(答案):


您必须在脚本中设置与您相同的重用标识符 正在代码中使用。如果这样做,出列将始终返回一个单元格, 你永远不需要实例化一个


首先:请确保以正确的大小写编写类和实例。类始终以大写开头,实例以小写开头!单元格不是零,这将是运行时异常和崩溃。我首先在调试器中检查单元格,特别是它的属性-如何以及何时创建所有标签单元格中的c?我觉得有趣的是,如果我在if语句中输入
cell.textLabel.text=@“test”
检查单元格是否等于nil,我的所有单元格都会显示“test”文本。因此
cell=[[GuestDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]
在不正确的时候被调用?这肯定会覆盖我对单元格的自定义?话虽如此,我认为你的权利可能与我如何使用UILabels有关。我只是将我的标签放入故事板中的单元格,并将插座连接到我的自定义单元格类(仅在中有标签声明,无其他内容)。然后在我的
cellforrowatinedexpath
方法中,我只是根据需要根据indexPath更改文本。那么我应该如何准确地处理它们呢?您必须在脚本中设置与在代码中使用的相同的重用标识符。如果这样做,出列将始终返回一个单元格,并且您永远不需要实例化一个单元格。