ios - 如何以编程方式删除 UITableView 的第 0 行?

标签 ios swift uitableview nsindexpath

我有一个具有表格 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/

相关文章:

iOS 如何检测变量 Swift 中的数据

sql-server - 如何用swift连接sql server

ios - 获取 "next"UITableViewCell 的 indexPath

ios - UISearchController 在 iPad 上显示全屏而不是弹出窗口

ios - 恢复应用程序状态时显示不确定的事件指示器?

ios - 导出屏幕截图 UIAutomation

ios - 空行和节标题的 Swift TableView 背景

iphone - 来自 Sqlite (FMDB) 的 UITableView 中的部分和索引

ios - 如何在cloudkit上存储数据

ios - swift 3 获取共享数据的用户信息