0

我创建了一个 tableviewcontroller 来处理 tableview 中的 4 个静态单元格。表格视图位于 4 个单元格的正下方。但是,最后一个单元格,即第 4 个单元格,根据第 3 个单元格的结果是可选的。

选择器返回一个值,如果值正确,它会重新加载表格视图以激活第 4 个单元格。

设置视图控制器

当我运行应用程序时,它会在加载 SettingsViewController 时崩溃,并出现以下错误:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法将具有标识符 Cell 的单元格出列 - 必须为标识符注册 nib 或类或连接情节提要中的原型单元格”

如果我有静态单元格,我认为我不需要重用标识符?

以下是相关代码:

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(self.showLastCell)
    {
        return 4;
    }
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...

    return cell;
}
4

2 回答 2

0

出列单元格用于具有动态单元格的表格视图。静态单元格表​​视图不必具有数据源 cellForRowAtIndexPath。因此,您可以安全地删除数据源方法 cellForRowAtIndexPath。

检查这个问题以获得更多解释:故事板静态单元格:dequeueReusableCellWithIdentifier 返回 nil

或者你可以使用这里提到的超级方法:UITableView with static cells without cellForRowAtIndexPath。如何设置清晰的背景?

于 2013-05-30T15:15:36.963 回答
0

正如您所说,您不需要将其出队,它只是静态单元格。

代替 :

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

利用 :

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

祝你好运 !

编辑:太慢了!

于 2013-05-30T15:18:36.663 回答