numberOfRowsInSection:未在reloadData上调用 [英] numberOfRowsInSection: not called on reloadData

查看:129
本文介绍了numberOfRowsInSection:未在reloadData上调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a UITableView that uses an array to list data. This works fine. I also have an UISearchBar for searching in that tableview. When data is matched in the tableviews array those rows are added to another mutable array, and cellForRowAtIndexPath: displays data from that mutable array instead.

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

But numberOfRowsInSection: is never called when I call reloadData. Therefore the tableview crashes when scrolling, because it's trying to get data from the mutable array, but for rows that are in the original array (which has more items)

我'已经调试了一段时间了,但不能为上帝的爱找到原因。 Datasource和Delegate连接在tableview中,因为它可以显示原始数组中的数据。

I've debugged for quite a while now, but can not for the love of god find the reasons for this. Datasource and Delegate are hooked up in the tableview, because it can show the data from the original array.

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


推荐答案

如何重装表格?
[table relaodData]; 对吧?
你的桌子是否连接到笔尖上的IBOutlet?
在重新加载时,已初始化?

how you reload your table? doing [table relaodData]; right? is your table is connected to IBOutlet on your nib? at the point of reloading , is table initialized?

你也可以发布崩溃信息。

you can post crash info too.

这篇关于numberOfRowsInSection:未在reloadData上调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆