[英]How to Group UITableView cells
我正在尝试将单元格分为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语句中的每个索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.