*** Assertion failure in -[UISearchResultsTableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.12/UITableView.m:7971
報(bào)錯(cuò)了。
情景:UITableView 和UISearchBar 組合使用尾菇,設(shè)置了代理遏乔,UISearchResultsUpdating
原因:當(dāng)點(diǎn)擊searchBar時(shí),會調(diào)用- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
方法式曲,此方法將會出現(xiàn)問題,方法示例:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"------%@,%@",[tableView class],[self.tableView class]);
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
cell.textLabel.text = self.dataSource[indexPath.row];
return cell;
}
此處的tableView是UISearchResultsTableView,通過打印出來的結(jié)果可以看到, 而當(dāng)UISearchResultsTableView去它的內(nèi)存池中尋找標(biāo)示為reuseIdentifier的Cell的時(shí)候就會出現(xiàn)錯(cuò)誤,而出現(xiàn)UISearchResultsTableView而不是原來的tableview的原因是我在xib中使用了UISearchBar缸榛。
解決方案有兩個(gè):
1.將tableview
替換成self.tableview
就可以了吝羞。
2.把UISearchBar改成UISearchViewController,初始化時(shí)這樣設(shè)為nil[[UISearchController alloc] initWithSearchResultsController:nil];
内颗。