Uitableview 对具有不同节号的表使用indexpath.setion

Uitableview 对具有不同节号的表使用indexpath.setion,uitableview,Uitableview,我有两个表视图,单元格根据它是哪个表视图进行配置,它们通过indexpath.section在cellforrowatinexpath方法中实现。但是,这两个表视图的节数不同。有办法解决这个问题吗?谢谢 当我说他们有不同的部门编号时,我的意思是: - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if(tableView==byTeam) { return [teamnameswitho

我有两个表视图,单元格根据它是哪个表视图进行配置,它们通过
indexpath.section
cellforrowatinexpath
方法中实现。但是,这两个表视图的节数不同。有办法解决这个问题吗?谢谢

当我说他们有不同的部门编号时,我的意思是:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if(tableView==byTeam) {
        return [teamnameswithoutRepeat count];
    } else {
        return [JSONPointsArray count];
    }
    // Return the number of sections.
}
当我在
cellforrowatinexpath中使用以下命令时:

label.text=[currentarray objectAtIndex: indexpath.section];

存在一个范围错误,因为
indexpath.section
太大,它使用
JSONPointsArray
来确定节数,但是当我运行应用程序时,team tableview的节数正确。

您的
cellForRow…
方法需要类似:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == byTeam) {
        // process the "byTeam" table using the teamnamesiwthoutRepeat array
    } else {
        // process the other table using the JSONPointsArray array
    }
}

谢谢,但我不确定你是否明白我的意思,我澄清了我的问题。再次感谢是的,这正是我所做的,但是当我放入:label.text=[currentarray objectAtIndex:indexpath.section];在每个if语句中,一个可以正常工作,但另一个会给我一个范围错误。两个表都有许多节,只有一行什么是
currentary
?使用您实际拥有的两个数组。是的,但即使这样做,我也会得到一个范围错误,对于我使用的by团队:cell.textLabel.text=[team nameswithoutrepeat objectatindex:indexpath.section],而对于另一个表,我也会做同样的事情:cell.textLabel.text=[jsonpointsarray ObjectAtIndeXPath.section],但我仍然会得到错误,对于JSon,范围错误与另一个是一致的,谢谢,为什么不发布真正给您带来问题的代码呢。