gpt4 book ai didi

objective-c - 当我不知道 UITableView 有多少个部分时,如何重新加载 UITableView 的数据?

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

我对如何在数据更改后重新加载 UITableView 中的单元格感到有点困惑。特别是,我感到困惑的是,新数据的部分可能比当前显示的部分更多或更少。我知道有 reloadSections:withRowAnimation: 方法,但这需要 1:1 替换,我可能有也可能没有。

我只是想告诉 UITableView 废弃所有内容并重新加载,就像第一次一样。我希望有人能对此有所启发。

提前致谢!

更新

这是我正在使用的代码,我发现问题是调用 reloadData 后单元格未出队...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

NSLog(@"%@", cell);

if (cell == nil) {
NSLog(@"%d; %d", indexPath.section, vehicle.inventoryCategoriesCount);

if (indexPath.section < vehicle.inventoryCategoriesCount) {
NSLog(@"Grouped cell");

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"] autorelease];

NSString *model = [[[vehicle.inventory filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"category == %@", [vehicle.inventoryCategories objectAtIndex:indexPath.section]]] valueForKeyPath:@"@distinctUnionOfObjects.model"] objectAtIndex:indexPath.row];

cell.textLabel.text = model;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d", [[vehicle.inventory filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"model == %@", model]] count]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
} else {
NSLog(@"Remove cell");

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] autorelease];

cell.textLabel.text = @"Remove an Item";
cell.textLabel.textColor = [UIColor redColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}

NSLog(@"Adding a cell");

return cell;
}

最佳答案

您可以在表格 View 上调用reloadData

[myTableView reloadData];

文档在这里: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html

关于objective-c - 当我不知道 UITableView 有多少个部分时,如何重新加载 UITableView 的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5446604/

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