从协议中刷新数据
Refreshing data from protocol
我有一个如下所示的协议:
protocol twitterModelProtocol: class {
func feedTwitterDatesDownloaded(items: [feedStruct])
}
在我的 UITableViewController 中,我有这段代码,它从协议中获取数据:
func feedTwitterDatesDownloaded(items: [feedStruct]) {
allData += items
self.tableView.reloadData()
}
我的问题是,如何在刷新函数中调用该函数?:
@objc private func refreshOptions(sender: UIRefreshControl) {
// What to do???
print("REFRESHED YEAH")
self.tableView.reloadData()
sender.endRefreshing()
}
如果您的 UITableViewController
class 符合 twitterModelProtocol
协议,那么您在 class 中所要做的就是:
self.feedTwitterDatesDownloaded(items: )
当然要为 "items" 参数发送正确的值。此外,"self" 是可选的。
还有一件事,您已经在 feedTwitterDatesDownloaded
中调用了 tableView.reloadData()
,因此在调用 feedTwitterDatesDownloaded
之后无需在 refreshOptions
中再次调用它.
我有一个如下所示的协议:
protocol twitterModelProtocol: class {
func feedTwitterDatesDownloaded(items: [feedStruct])
}
在我的 UITableViewController 中,我有这段代码,它从协议中获取数据:
func feedTwitterDatesDownloaded(items: [feedStruct]) {
allData += items
self.tableView.reloadData()
}
我的问题是,如何在刷新函数中调用该函数?:
@objc private func refreshOptions(sender: UIRefreshControl) {
// What to do???
print("REFRESHED YEAH")
self.tableView.reloadData()
sender.endRefreshing()
}
如果您的 UITableViewController
class 符合 twitterModelProtocol
协议,那么您在 class 中所要做的就是:
self.feedTwitterDatesDownloaded(items: )
当然要为 "items" 参数发送正确的值。此外,"self" 是可选的。
还有一件事,您已经在 feedTwitterDatesDownloaded
中调用了 tableView.reloadData()
,因此在调用 feedTwitterDatesDownloaded
之后无需在 refreshOptions
中再次调用它.