gpt4 book ai didi

iphone - numberOfRowsInSection : not called on reloadData

转载 作者:太空狗 更新时间:2023-10-30 03:15:39 24 4
gpt4 key购买 nike

我有一个 UITableView,它使用数组来列出数据。这很好用。我还有一个 UISearchBar 用于在该 tableview 中进行搜索。当数据在 tableviews 数组中匹配时,这些行被添加到另一个可变数组,cellForRowAtIndexPath: 显示来自该可变数组的数据。

但是当我调用 reloadData 时,numberOfRowsInSection: 从未被调用。因此 tableview 在滚动时崩溃,因为它试图从可变数组中获取数据,但对于原始数组(具有更多项)中的行

我已经调试了好久了,老天老是找不到原因。 Datasource 和 Delegate 连接在 tableview 中,因为它可以显示原始数组中的数据。

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"isSearching: %d", isSearching);
// Return the number of rows in the section.
if(!isSearching)
return [originalArray count];

NSLog(@"isSearching - Return searchCopyListOfItems");
return [searchCopyListOfItems count];
}

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

if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

if(!searching)
cell.textLabel.text = [originalArray objectAtIndex:indexPath.row];
else
cell.textLabel.text = [searchCopyListOfItems objectAtIndex:indexPath.row];

return cell;
}

最佳答案

如果 numberOfSections 返回 0,则不会调用 numberOfRowsInSection

关于iphone - numberOfRowsInSection : not called on reloadData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11468970/

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