ios7 with UIsearchBarController crashes?

那年仲夏 提交于 2019-12-12 04:38:41

问题


I am woking on ios7. In My app i am having UITableView and UISearchBar Controller. while implementing UISearchBar Controller my application crashes DUE TO following reason:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier listcell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

i am using custom UITabelViewCell.UISearchBarController delegate methods are also implemented.

Can any one provide me a better link or solution for this?

following is my code:

//----------------------code for search part------------------

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

Thanks


回答1:


You should put the following line in the method viewDidLoad:

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



来源:https://stackoverflow.com/questions/21046967/ios7-with-uisearchbarcontroller-crashes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!