带有搜索栏控制器的 ios 7 崩溃?

Posted

技术标签:

【中文标题】带有搜索栏控制器的 ios 7 崩溃?【英文标题】:ios7 with UIsearchBarController crashes? 【发布时间】:2014-01-10 14:34:29 【问题描述】:

我正在使用 ios7。 在我的应用程序中,我有 UITableView 和 UISearchBar 控制器。 在实现 UISearchBar 控制器时,我的应用程序崩溃了 由于以下原因:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法将具有标识符 listcell 的单元格出列 - 必须为标识符注册一个 nib 或类或连接情节提要中的原型单元格”

我正在使用自定义的 UITabelViewCell.UISearchBarController 委托方法也实现了。

谁能为此提供更好的链接或解决方案?

以下是我的代码:

//----------------------搜索部分的代码------------------

-(void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
 
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF Contains[cd] %@",searchText];

    searchResults = [_detailList filteredArrayUsingPredicate:resultPredicate];



-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString

    [self filterContentForSearchText:searchString scope:[[self.searchDisplayController.searchBar scopeButtonTitles]objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
    return YES;




-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

    return 1;


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

    if (tableView == self.searchDisplayController.searchResultsTableView)
    
        return [searchResults count];
    
    else
    return _detailList.count;



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

    static NSString *CellIdentifier = @"listcell";
//
   ListCell *listcell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];


        listcell.lbl_detail.text = _detailList [indexPath.row];
    listcell.lbl_Address.text = _detailList1 [indexPath.row];
    listcell.lbl_link.text = _detailList2 [indexPath.row];
    listcell.lbl_number.text = _detailList3 [indexPath.row];


    return listcell;




-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    
[(ContainerViewController *)self.parentViewController addDetailViewController];

谢谢

【问题讨论】:

您需要在情节提要中设置“listcell”标识符。 你能帮我解决这个问题吗 我已经在情节提要中设置了该标识符 @Nilesh,我已经更新了答案。请关注 【参考方案1】:

您应该在方法 viewDidLoad 中添加以下行:

[self.searchDisplayController.searchBar registerClass:[ListCell class] forCellReuseIdentifier:@"listcell"];

【讨论】:

以上是关于带有搜索栏控制器的 ios 7 崩溃?的主要内容,如果未能解决你的问题,请参考以下文章

iOS 7下UITableView section index相关崩溃

iOS 11.2 - 在带有大标题的导航栏中时,搜索控制器栏背景清晰

带有透明/模糊导航栏的 iOS 7 视图控制器布局问题

iOS 7 导航栏中的搜索栏

带有 UINavigationController 的 iOS 7 自定义当前转换

搜索栏导致应用程序在我的 ios 库中崩溃