问题
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