【发布时间】:2016-02-19 16:31:16
【问题描述】:
我正在开发一个外部动态可可库 (dylib),它在某些时候提供了一个带有表格视图和搜索栏的视图。 我在创建时有这个
- (void)viewDidLoad {
[super viewDidLoad];
NSBundle *frameworkBundle = [NSBundle bundleForClass:[self class]];
UINib *nib = [UINib nibWithNibName:CONTACT_CELL bundle:frameworkBundle];
[[self tableView] registerNib:nib forCellReuseIdentifier:CONTACT_CELL];
[self readContacts];
}
对于我的 tablerow 委托
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ContactCell *cell = [tableView dequeueReusableCellWithIdentifier:CONTACT_CELL];
if (cell == nil)
{
NSLog(@"Cell was empty!");
}
Contact *c = [contacts objectAtIndex:[indexPath row]];
[[cell labelName] setText: [c getName]];
[[cell labelPhone] setText: [c getPhone]];
return cell;
}
问题是当我点击搜索栏时,应用程序崩溃,因为:
* -[UISearchResultsTableView 中的断言失败 _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UITableView.m:7962 2016-02-19 17:07:00.404 HostApp[2233:20181] * 终止应用程序由于 未捕获的异常“NSInternalInconsistencyException”,原因: 'UITableView (; layer = ; contentOffset: {0, 0}; contentSize: {414, 528}>) 未能从其dataSource()'中获取单元格
如果我使用
[tableView dequeueReusableCellWithIdentifier:CONTACT_CELL forIndexPath: indexPath];
* -[UISearchResultsTableView dequeueReusableCellWithIdentifier:forIndexPath:] 中的断言失败, /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UITableView.m:6564 2016-02-19 17:37:08.254 HostApp[2691:28849] * 终止应用程序由于 未捕获的异常“NSInternalInconsistencyException”,原因:“无法 使具有标识符 ContactCell 的单元出列 - 必须注册一个 nib 或 标识符的类或连接原型单元 故事板'
【问题讨论】:
-
我尝试输入
[self.tableView registerClass:[UITableViewCell self] forCellReuseIdentifier:CONTACT_CELL],但没有成功。
标签: ios objective-c iphone uitableview dylib