2016-10-17 16 views
0
- (void)registerCellCallBack:(id<CellCallBack>)callBack { 
    int i = 0; 
    for(; i < _dataSource.count; ++i) { 
     id<CellCallBack> oldCallBack = _dataSource[i]; 
     if([callBack key] <= [oldCallBack key]) { 
      break; 
     } 
    } 
    if(i < _dataSource.count) { 
     [_dataSource insertObject:callBack atIndex:i]; 
    } else { 
     [_dataSource addObject:callBack]; 
    } 

    [self.table beginUpdates]; 
    [self.table insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]] withRowAnimation:UITableViewRowAnimationNone]; 
    [self.table endUpdates]; //--crashed here called "NSInternalInconsistencyException(SIGABRT)" 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return _dataSource.count; 
} 

甚至在iOS9是很好的代碼,在iOS10墜毀,但是當我調試我的代碼不會出現。當我打電話[的tableView insertRowsAtIndexPaths:withRowAnimation:],墜毀在iOS10

崩潰信息:

無效更新:在更新後的數 包含在現有部分中的行的部分0的行數無效(7) 必須等於的數包含在 更新(0)之前的那一行中包含的行,加上或減去從該部分插入或刪除 的行數(插入1個,刪除0),加上或減去移入或移出該部分的行的編號 (0移入,0移出)。

+0

只是刪除更新開始和結束的更新。而已。 –

回答

0

您需要更改按照如下:

[self.table reloadData]; 

[self.table beginUpdates]; 
[self.table insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]] withRowAnimation:UITableViewRowAnimationNone]; 
[self.table endUpdates]; //--crashed here called "NSInternalInconsistencyException(SIGABRT)" 
+0

是的,我已經取代了,但效率不高。我只是想知道在ios10中做了哪些更改。 – AZZ

+0

此代碼是否工作? – KKRocks

+0

工作得很好... – AZZ