Swift reason: 'attempt to insert row 10 into section 0, but there are only 10 rows in section

xiaoxiao2021-02-28  98

如果用的时NSArray或者NSDictionary来标识SectionRow数量,请在调用增删方法时更新好数据。并且在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)

转载请注明原文地址: https://www.6miu.com/read-46635.html

最新回复(0)