你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> NSInternalInconsistencyException attempt to delete row 2 from section 4 which only contains 0 rows b

NSInternalInconsistencyException attempt to delete row 2 from section 4 which only contains 0 rows b

編輯:IOS開發綜合

這裡講述的是NSInternalInconsistencyException attempt to delete row 2 from section 4 which only contains 0 rows before the update 問題原因的相關介紹,具體代碼請看下文

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]

通本學習您是不是更了解IOS開發了呢.感謝關注本站

【NSInternalInconsistencyException attempt to delete row 2 from section 4 which only contains 0 rows b】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

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