failed to obtain a cell from its dataSource 论坛找到答案
在iOS9 iPhone5s上面无缘无故tabelView崩了Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3505.16/UITableView.m:7927
2015-09-25 16:15:49.197 neatly-referral[10388:193809] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (<UITableView: 0x7f9f31905200; frame = (0 64; 320 504); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7f9f305a6700>; layer = <CALayer: 0x7f9f307bb160>; contentOffset: {0, 0}; contentSize: {320, 434.00999999999999}>) failed to obtain a cell from its dataSource (<AppointmentsViewController: 0x7f9f308b9a00>)' *** First throw call stack: ( 0 CoreFoundation 0x000000010c2e3f65 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010bd34deb objc_exception_throw + 48 2 CoreFoundation 0x000000010c2e3dca +[NSException raise:format:arguments:] + 106 3 Foundation 0x000000010b982ae2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198 4 UIKit 0x000000010a0b8879 -[UITableView _configureCellForDisplay:forIndexPath:] + 225 5 UIKit 0x000000010a0c36e1 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 828 6 UIKit 0x000000010a0c37c8 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74 7 UIKit 0x000000010a099650 -[UITableView _updateVisibleCellsNow:isRecursive:] + 3187 8 UIKit 0x000000010a0cc595 -[UITableView _performWithCachedTraitCollection:] + 92 9 UIKit 0x000000010a0b49ad -[UITableView layoutSubviews] + 218 10 UIKit 0x000000010a02511c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710 11 QuartzCore 0x0000000109cf536a -[CALayer layoutSublayers] + 146 12 QuartzCore 0x0000000109ce9bd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 13 QuartzCore 0x0000000109ce9a4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 14 QuartzCore 0x0000000109cde1d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277 15 QuartzCore 0x0000000109d0b9f0 _ZN2CA11Transaction6commitEv + 508 16 QuartzCore 0x0000000109d0c154 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92 17 CoreFoundation 0x000000010c20f9d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 18 CoreFoundation 0x000000010c20f947 __CFRunLoopDoObservers + 391 19 CoreFoundation 0x000000010c20559b __CFRunLoopRun + 1147 20 CoreFoundation 0x000000010c204e98 CFRunLoopRunSpecific + 488 21 GraphicsServices 0x000000010db7fad2 GSEventRunModal + 161 22 UIKit 0x0000000109f74676 UIApplicationMain + 171 23 neatly-referral 0x0000000107eba8cf main + 111 24 libdyld.dylib 0x000000010c7c792d start + 1 25 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException |
|
3 楼: 发表于: 2015-10-23 14:50 发自: Web Page
是因为你的cell被调用的早了。先循环使用了cell,后又创建cell。顺序错了。
eg:(正确的) @interface ViewController ()<UITableViewDataSource,UITableViewDelegate> { UINib * nib; } @end -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString * cellIdentifier = @"GameTableViewCell"; if (nib == nil) { nib = [UINib nibWithNibName:@"GameTableViewCell" bundle:nil]; [tableView registerNib:nib forCellReuseIdentifier:cellIdentifier]; NSLog(@"我是从nib过来的"); } GameTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; return cell; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用