ios - 重新加载 searchResultsTableView 时自定义单元格错误

标签 ios uitableview ios5 xcode4.2 uisearchdisplaycontroller

当我点击此按钮-[搜索]时,会出现弹出窗口。

如果我写下搜索词并单击“搜索”按钮,数据将填充到 NSMutableArray 中。

此搜索表使用“自定义单元格”。

我无法将“自定义单元格”与 NSMutableArray 中的数据结合起来。

重新加载“searchTableView”时出现错误。

我该怎么办?请帮帮我!~谢谢~

[错误]

2011-10-31 20:56:52.915 TheBE[1207:10403] abcd 2011-10-31 20:56:53.158 TheBE[1207:10403] * Assertion failure in -[UISearchResultsTableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072 2011-10-31 20:56:53.159 TheBE[1207:10403] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' ** First throw call stack: (0x12a2052 0x1753d0a 0x124aa78 0xc712db 0x381ee3 0x382589 0x36ddfd 0x37c851 0x327322 0x12a3e72 0x29ba92d 0x29c4827 0x294afa7 0x294cea6 0x294c580 0x12769ce 0x120d670 0x11d94f6 0x11d8db4 0x11d8ccb 0x1fae879 0x1fae93e 0x2e8a9b 0x1d68 0x1cc5 0x1)



    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

         //****** custom cell *********/
        SearchContentCell *cell = (SearchContentCell *)[tableView dequeueReusableCellWithIdentifier:@"SearchCell"];

        [cell.contentLabel setLineBreakMode:UILineBreakModeWordWrap];
        [cell.contentLabel setMinimumFontSize:FONT_SIZE];
        [cell.contentLabel setNumberOfLines:0];
        [cell.contentLabel setFont:[UIFont systemFontOfSize:FONT_SIZE]];
        [cell.contentLabel setTag:1];     

        ....... 
        cell.verseLabel.text = @"Test2" ; 
        cell.contentLabel.text = @"test"; 
         .......

        return cell;   

    }
    -(void)mockSearch:(NSString*)searchString  
    {   
        [_data removeAllObjects];   
        [request setEntity:entityBible]; 
    //        
        //create predicate   
        NSString *wildcardedString = [NSString stringWithFormat:@"*%@*",searchString];  
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"content like %@", wildcardedString];

        [request setPredicate:predicate]; 

        NSError *error;
        NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
        if (mutableFetchResults == nil) {
            // Handle the error;
            NSLog(@"eerror");
        }

        _data = mutableFetchResults;

         [self.searchDisplayController.searchResultsTableView reloadData];  

    }
    -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{

        [self mockSearch:searchBar.text]; 

    }

我认为错误部分:

[self.searchDisplayController.searchResultsTableView reloadData];

最佳答案

如果这确实是您的 tableView:cellForRowAtIndexPath: 方法的样子,那么如果 dequeueReusableCellWithIdentifier: 返回 nil,您就错过了分配新单元格的部分。

关于ios - 重新加载 searchResultsTableView 时自定义单元格错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7962107/

相关文章:

ios - 如何在单击按钮时在 SwiftUI 中为 TextField 设置文本

ios - 通过 UITableVIew 中的部分快速通用基本搜索功能

ios - 如何访问 UITableView 以重新加载数据?

ios - "Collection ... mutated while being enumerated"崩溃

ios - 无法在我的音乐播放器应用程序上播放音乐

ios - UISwitch:之前做了什么:附加选择器,还是改变状态?

ios - 带有 UIStackViews 的动态 UITableView 单元格高度

iphone - 在 xCode 中对 Web 服务收费时出现重复的 MKAnnotations

objective-c - 在 xcode 中搜索硬编码文本

objective-c - AFNetworking 中的 ASIFormDataRequest?