我正在尝试将单元格分为uitableview的单元格制作一个tableview。我环顾了一下,发现了如何将其分成几部分,尽管我坚持让它们像应该以组的形式出现一样,而不是由三组组成,每组中都有所有单元格,这就是我现在所拥有的经过一些研究后得到了到目前为止:
-(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语句中的每个索引。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句