在 tableview 目标 c 的搜索栏上输入文本时应用程序崩溃

Posted

技术标签:

【中文标题】在 tableview 目标 c 的搜索栏上输入文本时应用程序崩溃【英文标题】:App is crashing while entering text on search bar for tableview objective c 【发布时间】:2016-12-01 12:09:31 【问题描述】:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  
if (tableView == self.searchDisplayController.searchResultsTableView) 
   return searchResults.count; 
 else  
    return self.countOfLocArr.count;
 


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  

    AtmLocationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 
    if(!cell)  
        AtmLocationTableViewCell *cell = [[AtmLocationTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
     
    NSMutableDictionary *locDictionary; 
    if(tableView == self.searchDisplayController.searchResultsTableView) 
     locDictionary = searchResults[indexPath.row];
    else  
    cell.placeName.text = locDictionary[@"name"]; 
    return cell;
    

遇到错误

* -[UISearchResultsTableView _configureCellForDisplay:forIndexPath:] 中的断言失败,/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.7/UITableView.m:7971 2016-12-01 18:21:04.096 Mobee[6459:2145589] * 终止应用程序由于 未捕获的异常“NSInternalInconsistencyException”,原因: 'UITableView (; 层 = ; contentOffset: 0, 0; contentSize: 320, 396>) 未能从其获取单元格 数据源 ()' *** 第一次抛出调用堆栈:(0x20fb9b8b 0x20776dff 0x20fb9a61 0x217a072b 0x256d64a3 0x258d3cb9 0x258d3d91 0x258c326d 0x256673bd 0x2579129f 0x256ec46d 0x257923e3 0x257920bb 0x25791f2d 0x255c2521 0x255c24b1 0x255aa3eb 0x25791c75 0x255ccd9f 0x25760b5b 0x2575饲料 0x258e967f 0x25ea5f73 0x2575fc53 0x2598e135 0x2598dd5f 0x255b5355 0x217e6867 0x20f7ba67 0x20f7b657 0x20f799bf 0x20ec8289 0x20ec807d 0x224e4af9 0x255f32c5 0xde303 0x20b74873) libc++abi.dylib: 终止 带有未捕获的 NSException 类型的异常

【问题讨论】:

这两个委托方法正在分配。它的崩溃...... self 表视图数据源和委托。 @ReetaChainani 简要告诉我们你想做的整个事情,你面临什么问题。粘贴您尝试过的代码。如果我们了解您的实际问题,我们将很乐意为您提供帮助。编辑您的问题。 :) 【参考方案1】:

检查这个:

1) 您从 tableView:numberOfRowsInSection: 返回一个大于数组计数的数字。不要。

2) 您的一个或多个 cell# 插座未连接到您的笔尖,或者未连接到 UITableViewCell(或子类)。正确连接它们。

更多信息请参考:https://***.com/a/14192093/3901620

【讨论】:

【参考方案2】:

cellForRowAtIndexPath 可能会返回 nil

检查这些:Assertion Failure 1、Assertion Failure 2 和 Assertion Failure 3

【讨论】:

以上是关于在 tableview 目标 c 的搜索栏上输入文本时应用程序崩溃的主要内容,如果未能解决你的问题,请参考以下文章

Swift 搜索栏 - 使用 Alamofire 请求更新表格视图

如何在 iOS 10 的目标 c 中使用 uisearchbar?

iOS:如何使用目标 c 实现搜索控制器以及如何在运行时调用 API,即当我开始输入搜索控制器时?

如何在目标c中的tableview上方实现一个选择/取消选择所有按钮?

在目标 c 中扩展 tableview 时按钮不起作用?

TableView 中的搜索栏:输入搜索文本字符串的最后一个字符时应用程序崩溃