您的位置:首页 > 移动开发 > Swift

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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  swift
相关文章推荐