【发布时间】:2018-07-30 11:15:01
【问题描述】:
在我的应用中,我正在根据用户的位置更新UITableView。我在CLLocationManagerDelegate 内执行此操作。现在,我的UITableView 将继续重新加载,因此不会绘制任何东西。当我注释掉reloadData() 电话时,一切都很好(当然没有位置)。当我重新添加它时,print() 会执行一次。之后,表格不断重新加载。
extension RestaurantsViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if (locations.count > 0) {
if (location?.coordinate.longitude != locations[0].coordinate.longitude && location?.coordinate.latitude != locations[0].coordinate.latitude) {
location = locations[0]
print("will reload table")
self.tableView.reloadData()
}
}
}
}
有什么办法可以解决这个问题吗?
【问题讨论】:
-
别想了:确保
self.tableView.reloadData()正在主线程上执行 -
好主意,我确实添加了它,但它没有任何改变。 ??????
-
确保您的表视图委托或数据源函数中没有任何
reloadData()。
标签: swift uitableview cllocationmanager