我试图让一个UITableView呈现一个段的确定数量的行,但即使当我验证其数据源正在为numberOfRowsInSection返回x行时,表视图显示x-1。UITableView显示与数据源相比不一致的行数
的例外意外的行为是,如果numberOfRowsInSection小于3
我甚至放的cellForRowAtIndexPath一个断点,我证实了它被称为针对未出现该行。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == SectionNumber_One) {
return 6;
} else {
return self.numberOfProjectRows; // This returns x, but x-1 rows are being shown
}
}
例如,如果self.numberOfProjectRows为5,则第二部分只显示4行。
如果我手动将它增加到6,它显示5行,但应该在第5个位置的数据不在那里。
它似乎与屏幕尺寸无关,因为我在iPad上测试了它,结果相同。
这是怎么发生的?有一些其他可能的修改器的行数在一节中?
我附上截图,如果它有任何帮助。
编辑 -这里是我的委托方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Cell with reuse identifier setup
if (section == SectionNumber_One) {
// cell setup for section one that's showing up ok
} else if (section == SectionNumber_Two) {
UITextField *projectField = cell.projectTextField;
if ([self.userProjectKeys count] > row) {
projectField.text = self.availableProjects[self.userProjectKeys[row]];
}
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Hide the password row for existing users
if (indexPath.row == FieldTag_Password && ![self.user.key vol_isStringEmpty]) {
return 0.0f;
} else {
return UITableViewAutomaticDimension;
}
}
你能展示一些你的viewcontroller代码吗? –
问题可能不在于您的数据源方法,而是您的委托方法。如果你没有为单元格返回正确的高度,它将不会显示出来。 **您需要将代码添加到您的问题的实际委托方法中**如果您需要进一步帮助,请在其中设置单元格的高度。如果您在数据源中写入1000个单元,则无关紧要。如果你不返回高度,他们不会出现。您还应该将代码添加到您的cellForRow方法中。 – 2017-02-14 01:05:39
@Sneak非常感谢你!你钉了它。我改变了只考虑第0部分的行的高度,并忘记它也会修改第1部分。 –