【发布时间】: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,我已经更新了答案。请关注
标签: objective-c ios5 ios6 ios7 xcode5