ios 使用 Swift 在表格视图中重新加载单元格数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26709537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
reload cell data in table view with Swift
提问by Martin
how is it possible to reload data for a cell in my table view? I want to do a request to my Server and the server responses JSON. At the moment I implemented the request and the response handling and I can show the data in my cells. But I want that the server only responses maybe ten datasets. When I scroll to the end of the table view with my ten cells in the app I want to do the next request to my server and the server delivers the next ten datasets and so on. I work with Swift as the programming language.
如何在我的表格视图中重新加载单元格的数据?我想向我的服务器发出请求,服务器响应 JSON。目前我实现了请求和响应处理,我可以在我的单元格中显示数据。但我希望服务器只响应十个数据集。当我在应用程序中使用我的十个单元格滚动到表格视图的末尾时,我想向我的服务器发出下一个请求,然后服务器提供接下来的十个数据集,依此类推。我使用 Swift 作为编程语言。
THX!
谢谢!
回答by YogevSitton
You can use self.tableView.reloadData()
in order to reload your entire table or self.tableView.reloadRowsAtIndexPaths(paths, withRowAnimation: UITableViewRowAnimation.None)
in order to reload a specific cell.
您可以使用self.tableView.reloadData()
以重新加载整个表格或self.tableView.reloadRowsAtIndexPaths(paths, withRowAnimation: UITableViewRowAnimation.None)
重新加载特定单元格。
You can read more about the UITableView class here
您可以在此处阅读有关 UITableView 类的更多信息
回答by Usman Nisar
To reload visible cells of tableview in Swift 3.0
在 Swift 3.0 中重新加载 tableview 的可见单元格
pTableView.beginUpdates()
pTableView.reloadRows(at: pMessagesTableView.indexPathsForVisibleRows!, with: .none)
pTableView.endUpdates()
回答by Mayank Jain
Try this...
尝试这个...
Swift 2.0
斯威夫特 2.0
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.tableView.reloadData()
})
Swift 3.0
斯威夫特 3.0
DispatchQueue.main.async {
self.tableview.reloadData()
}
回答by Saurabh Prajapati
you can get Array of visible Cell by using TableView
Function tableView.visibleRows()
or You Can Get IndexPath
of Visible Rows By tableView.indexPathsForVisibleRows()
! and then you can reload table by tableView.reloadData()
Function!
您可以使用TableView
FunctiontableView.visibleRows()
或 You Can Get IndexPath
of Visible Rows By 来获取可见单元格数组tableView.indexPathsForVisibleRows()
!然后您可以按tableView.reloadData()
功能重新加载表!
look at following links
看看下面的链接
you can read about UITableView
Class Here
你可以在这里阅读UITableView
Class