在Swift中刷新基于Int的UITableView的某一行 [英] Refresh certain row of UITableView based on Int in Swift
问题描述
我是Swift的初级开发人员,我正在创建一个包含UITableView的基本应用程序。我想使用以下方式刷新表的某一行:
I am a beginning developer in Swift, and I am creating a basic app that includes a UITableView. I want to refresh a certain row of the table using:
self.tableView.reloadRowsAtIndexPaths(paths, withRowAnimation: UITableViewRowAnimation.none)
我希望刷新的行来自一个名为rowNumber的Int
and I want the row that will be refreshed to be from an Int named rowNumber
问题是,我不知道怎么做,我搜索过的所有线程都是Obj-C
The problem is, I don't know how to do this and all the threads I've searched are for Obj-C
任何想法?
推荐答案
您可以使用该行创建 NSIndexPath
然后重新加载它的部分编号:
You can create an NSIndexPath
using the row and section number then reload it like so:
let indexPath = NSIndexPath(forRow: rowNumber, inSection: 0)
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)
在这个例子中,我是假设您的表只有一个部分(即0),但您可以相应地更改该值。
In this example, I've assumed that your table only has one section (i.e. 0) but you may change that value accordingly.
Swift 3.0的更新:
let indexPath = IndexPath(item: rowNumber, section: 0)
tableView.reloadRows(at: [indexPath], with: .top)
这篇关于在Swift中刷新基于Int的UITableView的某一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!