技术文章分类(180)

技术随笔(11)

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()
    }
posted @ 2014-07-16 14:19  坤哥MartinLi  阅读(1480)  评论(0编辑  收藏  举报