【发布时间】:2014-07-14 10:26:52
【问题描述】:
#pragma Search Methods
-(void)filterContentForSearchText:(NSString *)searchText scope:(NSString *)scope
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@",searchText];
_AramaSonuclari = [_TarifAdi filteredArrayUsingPredicate:predicate];
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
return YES;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if (tableView == self.searchDisplayController.searchResultsTableView)
{
return [_AramaSonuclari count];
}
else
{
return _TarifAdi.count;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell" forIndexPath:indexPath];
cell.tag = indexPath.row;
//cell.imageView.image = nil;
if (tableView == self.searchDisplayController.searchResultsTableView)
{
cell.TitleLabel.text = _AramaSonuclari[indexPath.row];
}
else
{
cell.TitleLabel.text = _TarifAdi[indexPath.row];
}
return cell;
}
我们的问题,当我们尝试在搜索栏中输入任何字符时,应用程序崩溃,我们确实调试了我们的代码工作而没有错误。我们认为,我们的问题在于故事板连接;我还添加了一张图片。当我们删除 searchBar 引用的 outlet 时,我们可以输入一些东西,但当然代码在没有连接的情况下无法工作。
错误日志:
2014-07-14 13:29:08.577 SevgiLezzeti[3839:60b] *** 断言失败 -[UISearchResultsTableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:5439
2014-07-14 13:29:08.582 SevgiLezzeti[3839:60b] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法使具有标识符 TableViewCell 的单元格出列 - 必须注册一个 nib 或一个标识符的类或连接故事板中的原型单元'
【问题讨论】:
-
什么是崩溃日志,你是如何确定你的代码是正确的
-
您在 IB 中是否将单元格 id 定义为“TableViewCell”?
-
是的,当我尝试 searchBar 时,我定义了我的代码工作没有搜索仍然没有问题,但是当我尝试输入内容时立即崩溃
-
在将单元格出列时尝试使用 self.tableView 而不是 tableView,因为 tableView 可能不是已定义单元格 ID 的实例
-
这与Xcode无关。
标签: ios objective-c