Iphone 如何将UITableView单元格分组

Iphone 如何将UITableView单元格分组,iphone,objective-c,uitableview,grouped-table,Iphone,Objective C,Uitableview,Grouped Table,我正在尝试创建一个tableview,其中单元格被拆分为多个部分,uitableview被分组。我环顾四周,发现了如何将它分成几个部分,尽管我一直坚持让它们以应有的方式分组出现,而不是三组,每个组中都有所有的细胞,这就是我目前所拥有的,这是我在做了一点研究后得到的: -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableV

我正在尝试创建一个tableview,其中单元格被拆分为多个部分,uitableview被分组。我环顾四周,发现了如何将它分成几个部分,尽管我一直坚持让它们以应有的方式分组出现,而不是三组,每个组中都有所有的细胞,这就是我目前所拥有的,这是我在做了一点研究后得到的:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = nil;
    if ([indexPath section] == 0) {
        if (indexPath.row == 0) {
            cell = cell1;
        } else if (indexPath.row == 1) {
            cell = cell2;
        } else if (indexPath.row == 2) {
            cell = cell3;
        }   
    }
    if ([indexPath section] == 1) {
        if (indexPath.row == 0) {
            cell = cell4;
        } else if (indexPath.row == 1) {
            cell = cell5;
        } else if (indexPath.row == 2) {
            cell = cell6;
        }
    }
    if ([indexPath section] == 2) {
        if (indexPath.row == 0) {
            cell = cell7;
        }
    }
    return cell;
}
但是,当我运行并转到此视图时,应用程序崩溃,并且在nslog框中出现以下错误:

*** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:5471

提前感谢

对于每个新节,行索引从零开始

例如:

if ([indexPath section] == 2) {
    if (indexPath.row == 3) {
应该是:

if ([indexPath section] == 2) {
    if (indexPath.row == 0) {

此外,节索引也从零开始,因此您可能希望减少if语句中的每个索引。

我尝试过,虽然似乎不起作用,但会用我现在的内容更新我的问题。这看起来是一种完全错误的方法。什么是cell1、cell2等?通过将数据源数组设置为数组数组(通常)来获取节。在“节数”中,返回数组的计数;在“行数”中,返回每个内部数组的计数。@rdelmar我正在使用xib上的uitableview单元格,并将它们拉入。这就是它们的用途,你有7种不同类型的单元格吗?是的,我有,如果我删除所有与节相关的内容,那么它就会工作,但当然没有节,你似乎不会在cellFroRowAtIndexPath中添加任何内容。是否在xib中添加内容?