首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >numberOfRowsInSection:未在reloadData上调用

numberOfRowsInSection:未在reloadData上调用
EN

Stack Overflow用户
提问于 2012-07-13 18:46:17
回答 7查看 15.5K关注 0票数 17

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

但是当我调用reloadData时,numberOfRowsInSection:永远不会被调用。因此,tableview在滚动时崩溃,因为它试图从可变数组中获取数据,但获取的是原始数组中的行(包含更多项)

我已经调试了很长一段时间,但看在上帝的份上找不到原因。数据源和委派被挂接到tableview中,因为它可以显示来自原始数组的数据。

代码语言:javascript
复制
    - (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;
    }
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11468970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档