gpt4 book ai didi

ios - UITableView 显示与数据源相比不一致的行数

转载 作者:行者123 更新时间:2023-11-29 00:29:40 28 4
gpt4 key购买 nike

我试图使 UITableView 呈现一个部分的确定行数,但即使我验证其数据源为 numberOfRowsInSection 返回 x 行数, TableView 也显示 x-1。

此意外行为的异常(exception)情况是 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 上进行了测试,结果相同。

为什么会发生这种情况?节中的行数是否还有其他可能的修饰符?

如果有任何帮助,我会附上屏幕截图。

UITableView screenshot

编辑-这是我的委托(delegate)方法:

- (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;
}
}

最佳答案

问题可能不在您的数据源方法中,而是在您的Delegate 方法中,tableView(_:heightForRowAt:) .

如果您没有为单元格返回正确的高度,它就不会显示。

即使您在数据源中写入 1000 个单元格也没关系。如果您不返回高度,它们将不会显示。

关于ios - UITableView 显示与数据源相比不一致的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42214968/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com