我正在研究一個外部動態可可庫(dylib),它在某些時候提供了一個帶有tableview和搜索欄的視圖。 我有這個在上創建搜索欄導致應用崩潰在我的ios庫
- (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;
}
問題是,當我點擊搜索欄的應用chrashes因爲:
*斷言失敗 - [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: *終止應用程序由於 未捕獲的異常「NSInternalInconsistencyException」,原因:「無法 出列具有標識符ContactCell細胞 - 必須註冊一個筆尖或 使標識符的一類或一 故事板連接原型細胞」
http://stackoverflow.com/questions/34250595/failed-to-obtain-a-cell-from-its-datasource? – Larme
我試着把'[self.tableView registerClass:[UITableViewCell self] forCellReuseIdentifier:CONTACT_CELL]',但沒有運氣。 – Picci