你好,歡迎來到IOS教程網

 Ios教程網 >> IOS使用技巧 >> IOS技巧綜合 >> NSInternalInconsistencyException attempt to delete row 2 from section 4 which only contains 0 rows before the update 問題原因

NSInternalInconsistencyException attempt to delete row 2 from section 4 which only contains 0 rows before the update 問題原因

編輯:IOS技巧綜合
[摘要]本文是對NSInternalInconsistencyException attempt to delete row 2 from section 4 which only contains 0 rows before the update 問題原因的講解,對學習IOS蘋果軟件開發有所幫助,與大家分享。

insertRowsAtIndexPaths 和deleteRowsAtIndexPaths 同numberOfRowsInSection的關系

如果不處理好這個關系,大概所有的問題都是這樣的:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 6. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (9), plus or minus the number of rows inserted or deleted from that section (0 inserted, 3 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 2 from section 4 which only contains 0 rows before the update'

大楖是說,numberOfRowsInSection 返回的數字和 insert / delete 後,section 所包含的行數不一致。

在 tableView 的 endUpdates 方法之前,應該對標志變量做處理。endUpdates 後,會重新刷新 tableView ,numberOfRowsInSection 會重新被調用。

解決方法有兩種:

1,如上所說處理好標志變量:

if ([wwtableview numberOfRowsInSection:4]>2) {}

2,tableview beginUpdates之前的行數對應的是前一個數據源,開始reloadcell時tableview並不知道數據源發生了變化

[wwtableviewreloadData]

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved