swift insertRows and deleteRows注意事项
注意:self.datas是数据源
就是必须先处理数据源,再进行cell的操作。
func switchButtonAction(isButtonOn:Bool){ self.tableview.beginUpdates() if isButtonOn==true{ var title2:String = "重置手势密码" self.datas.addObject(title2) var indexPaths:NSMutableArray = NSMutableArray() var indexPath:NSIndexPath = NSIndexPath(forRow:1,inSection:0) indexPaths.addObject(indexPath) self.tableview.insertRowsAtIndexPaths(indexPaths,withRowAnimation:.Top) }else{ self.datas.removeLastObject() var indexPaths:NSMutableArray = NSMutableArray() var indexPath:NSIndexPath = NSIndexPath(forRow:1,inSection:0) indexPaths.addObject(indexPath) self.tableview.deleteRowsAtIndexPaths(indexPaths,withRowAnimation:.Middle) println("false") } self.tableview.endUpdates() }