如何解决如何手动调用“tableView numberOfRowsInSection”函数
我正在制作一个从 CloudKit 获取数据并将其显示在 tableview 中的应用程序。在 viewDidLoad 结束时,我调用了一个不同的函数来获取这些数据并对其进行过滤。但是,我的 tableView numberOfRowsInSection 函数似乎在我的获取函数之前被调用,所以我的 tableView 中没有行,因为还没有通过我的获取函数,并且我分配为背景视图的视图弹出,因为它当我没有行时应该。我想知道,有没有办法在我的自定义函数结束时再次调用我的 tableView numberOfRowsInSection 函数,以便它可以更新 tableView?我知道如何调用普通函数:
function(any parameters here)
不过,我似乎不知道如何称呼它:
tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int
假设我无法将获取函数代码移动到 ViewDidLoad 中。
解决方法
您不直接调用 numberOfRowsInSection
。只需像这样在您的 reloadData()
上调用 tableView
:
yourAsynchronousFunctionThatGetsYourDataFromCloudKit(){ records in
//Set your data source with the CKRecords you got from CloudKit
self.items = records
//Reload the table
self.tableView.reloadData()
}
//This gets called by reloadData()
func tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
return items.count
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。