我是 Swift 的初学者,我正在创建一个包含 UITableView 的基本应用程序。我想使用以下命令刷新表格的某一行:
self.tableView.reloadRowsAtIndexPaths(paths, withRowAnimation: UITableViewRowAnimation.none)
我希望将要刷新的行来自一个名为 rowNumber 的 Int
问题是,我不知道该怎么做,而且我搜索过的所有线程都是针对 Obj-C 的
有什么想法吗?
最佳答案
您可以使用行号和节号创建一个 NSIndexPath
,然后像这样重新加载它:
let indexPath = NSIndexPath(forRow: rowNumber, inSection: 0)
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)
在此示例中,我假设您的表格只有一个部分(即 0),但您可以相应地更改该值。
Swift 3.0 更新:
let indexPath = IndexPath(item: rowNumber, section: 0)
tableView.reloadRows(at: [indexPath], with: .top)
关于ios - 在 Swift 中根据 Int 刷新 UITableView 的某行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28206492/