Swift reason: 'attempt to insert row 10 into section 0, but there are only 10 rows in section
2017-06-07 15:24
465 查看
如果用的时NSArray或者NSDictionary来标识Section和Row数量,请在调用增删方法时更新好数据。并且在beginUpdate和
enUpdate方法中间增删操作。
self.tableView.beginUpdates()
//数组元素+1
self.lists.append(self.lists.count+1)
//底部插入一行数据
let bottomIndexPath =
IndexPath.init(row:
self.lists.count-1, section:
0)
let insertIndexPaths =
Array.init(arrayLiteral: bottomIndexPath)
//同样,将数据加到数据列表后刷新
self.tableView.insertRows(at: insertIndexPaths, with: .automatic)
self.tableView.endUpdates()
//滚动位置
self.tableView.scrollToRow(at: bottomIndexPath, at: .bottom,
animated: true)
enUpdate方法中间增删操作。
self.tableView.beginUpdates()
//数组元素+1
self.lists.append(self.lists.count+1)
//底部插入一行数据
let bottomIndexPath =
IndexPath.init(row:
self.lists.count-1, section:
0)
let insertIndexPaths =
Array.init(arrayLiteral: bottomIndexPath)
//同样,将数据加到数据列表后刷新
self.tableView.insertRows(at: insertIndexPaths, with: .automatic)
self.tableView.endUpdates()
//滚动位置
self.tableView.scrollToRow(at: bottomIndexPath, at: .bottom,
animated: true)
相关文章推荐
- NSInternalInconsistencyException', reason: 'attempt to insert row 0 into section 0, but there are on
- vue中出现 There are multiple modules with names that only differ in casing的问题
- solr或lucene中出现there are more terms than documents in field "name", but it's impossible to sort on tokenized fields异常
- There are multiple modules with names that only differ in casing. This can lead to unexpected....
- Android的工作室 - 在项目中的所有文件名都是红色,但没有错误(Android Studio - All file names in project are red but there are
- cellForRowAtIndexPath not called but numberOfRowsInSection called
- There Are Only Four Jobs in the Whole World – Are You in the Right One?
- HDU 4627 There are many unsolvable problem in the world.It could be about one or about zero.But this time it is about bigger number.
- How to determine whether there are circles in a singly linked list?
- error: 'for' loop initial declarations are only allowed in C99 mode
- error: 'for' loop initial declarations are only allowed in C99 mode
- The specified type member 'IsLock' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
- error: 'for' loop initial declarations are only allowed in C99 mode
- 【内存管理-问题实例】为什么执行了numberOfRowsInSection方法后,dataArray的retainCount就少了一个? 谁把它 release了?
- ssh整合的时候出现错误:Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)
- CodeBlocks:for loop initial declarations are only allowed in c99 mode
- error: 'for' loop initial declarations are only allowed in C99 mode 的原因及解决办法
- [!] Pods written in Swift can only be integrated as frameworks; add `use_frameworks!` to your Podfil
- error: ‘for’ loop initial declarations are only allowed in C99 mode
- error: 'for' loop initial declarations are only allowed in C99 mode