我有一个具有表格 View 的应用程序。每隔一分钟左右,我希望 UITableView 的第一行消失。让它动画化会很好。我假设我需要使用这样的东西:
let myNSIndexPath = [NSIndexPath(forRow: 0, inSection: 0)]
mainTableView.deleteRowsAtIndexPaths(myNSIndexPath, withRowAnimation:UITableViewRowAnimation.Fade)
这行不通。我不确定如何正确使用 IndexPath。我的表只有一个部分,我总是希望删除索引 0 处的单元格。必须做什么才能使其正常工作?
最佳答案
单向
使用removeAtIndex
yourarray.removeAtIndex(indexPath.row)
不要忘记重新加载 TableView
tableView.reloadData()
第二种方式
yourIndexPath = [NSIndexPath(forRow: 0, inSection: 0)]
yourtable.beginUpdates() //if you are performing more than one operation use this
yourarray.removeObjectAtIndex(myNSIndexPath.row)
yourtable.deleteRowsAtIndexPaths(NSArray(object: yourIndexPath), withRowAnimation: UITableViewRowAnimation.Left)
yourtable.endUpdates() //if you are performing more than one operation use this
得到帮助
关于ios - 如何以编程方式删除 UITableView 的第 0 行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34523352/