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;
原文地址:https://www.cnblogs.com/wangxiaorui/p/5155714.html