首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UITableView reloadData循环

UITableView reloadData循环
EN

Stack Overflow用户
提问于 2018-07-30 19:15:01
回答 1查看 41关注 0票数 0

在我的应用程序中,我正在根据用户的位置更新UITableView。我在CLLocationManagerDelegate中做这件事。现在,发生的情况是,我的UITableView将不断重新加载,因此不会绘制任何内容。当我注释掉reloadData()调用时,一切都很好(当然没有位置)。当我重新添加它时,print()被执行一次。在此之后,表将继续重新加载。

代码语言:javascript
运行
复制
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()
            }
        }
    }
}

你知道我该怎么解决这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2018-07-30 19:38:31

你需要在找到你的位置后使用stopUpdating。重新加载tableView后添加此manager.stopUpdatingLocation()

代码语言:javascript
运行
复制
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()
                manager.stopUpdatingLocation()
            }
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51592741

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档