Ios 使用UISearchDisplayController时显示搜索结果崩溃

Ios 使用UISearchDisplayController时显示搜索结果崩溃,ios,uitableview,uisearchdisplaycontroller,Ios,Uitableview,Uisearchdisplaycontroller,我尝试使用CoreData在我的TableView中实现SearchBarView控制器。但是,当我点击搜索栏时,应用程序崩溃,我得到以下错误: -[UISearchResultsTableView]中的断言失败 dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit/UIKit-2935.137/UITableView.m:5439 ***由于未捕获的异常“NSInternalInconsistencyExcep

我尝试使用CoreData在我的TableView中实现SearchBarView控制器。但是,当我点击搜索栏时,应用程序崩溃,我得到以下错误:

-[UISearchResultsTableView]中的断言失败 dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit/UIKit-2935.137/UITableView.m:5439
***
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法将单元格出列。” 带标识符单元格-必须为 标识或连接故事板中的原型单元

在没有搜索栏的情况下,我的表格内容如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...
    NSManagedObject *device = [self.inventory objectAtIndex:indexPath.row];
    [cell.textLabel setText:[NSString stringWithFormat:@"%@", [device valueForKey:@"productName"]]];
    //[cell.detailTextLabel setText:[device valueForKey:@"company"]];

    return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...
    NSManagedObject *device = nil;
    if (tableView == self.searchDisplayController.searchResultsTableView)
        {device = [searchResults objectAtIndex:indexPath.row];}
    else
        {device = [self.cart objectAtIndex:indexPath.row]; }

    [cell.textLabel setText:[NSString stringWithFormat:@"%@", [device valueForKey:@"productName"]]];

    return cell;
}
工作完美

因此,现在我尝试如下方式显示SearchbarViewControllerContent:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...
    NSManagedObject *device = [self.inventory objectAtIndex:indexPath.row];
    [cell.textLabel setText:[NSString stringWithFormat:@"%@", [device valueForKey:@"productName"]]];
    //[cell.detailTextLabel setText:[device valueForKey:@"company"]];

    return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...
    NSManagedObject *device = nil;
    if (tableView == self.searchDisplayController.searchResultsTableView)
        {device = [searchResults objectAtIndex:indexPath.row];}
    else
        {device = [self.cart objectAtIndex:indexPath.row]; }

    [cell.textLabel setText:[NSString stringWithFormat:@"%@", [device valueForKey:@"productName"]]];

    return cell;
}
但这不起作用

如果您必须了解我的搜索栏(应该)的工作原理:


必须在viewDidLoad方法中为search tableView注册单元格,例如:

  [self.searchDisplayController.searchResultsTableView registerNib:[UINib nibWithNibName:<Nib Name> bundle:nil] forCellReuseIdentifier:<cellIdentifier>]
[self.searchDisplayController.searchResultsTableView注册表项nb:[UINib nibWithNibName:bundle:nil]强制重用标识符:]

同一问题的可能重复,但不同的解决方案是否有其他解决方案?您所说的“其他解决方案”是什么意思?从重复问题的答案中,您尝试了哪些解决方案?他们为什么不工作?对不起。。。好的,所以我通过重复主题解决了崩溃应用程序的问题。但当我在搜索栏中键入字母时,返回“无结果”。我如何确定搜索栏正在我的CoreData中搜索?还是说这个“没有结果”——错误与此无关?