在iPhone SDK上等待CLLocationManagerDelegate的didUpdateToLocation方法时,不会填充UITableView [英] UITableView doesn't populate when waiting for CLLocationManagerDelegate 's didUpdateToLocation method on iPhone SDK

查看:80
本文介绍了在iPhone SDK上等待CLLocationManagerDelegate的didUpdateToLocation方法时,不会填充UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用一个单元格数组填充UITableview。我通常从viewDidLoad方法执行此操作,但是这次我要根据位置填充数组。下面是我的界面的第一行:

I'm trying to populate a UITableview with an array of cells. I usually do this from the viewDidLoad method but this time I want to populate the array based on location. Below is the first line of my interface:

@interface RootViewController : UITableViewController 
<UITableViewDelegate, UITableViewDataSource, CLLocationManagerDelegate> {

在实现文件中,viewDidLoad方法如下所示:

In the implementation file the viewDidLoad method looks like this:

- (void)viewDidLoad {

    // for location
    self.locationManager = [[CLLocationManager alloc] init];
    [locationManager startUpdatingLocation];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;


    [super viewDidLoad];
}

我在didUpdateToLocation方法中填充了单元格数组:

I populate the array of cells in the didUpdateToLocation method:

    self.title = @"Open Buildings";

NSMutableArray *buildingArray = [[NSMutableArray alloc] initWithObjects:building1, 

self.controllers = array;

在找到位置但未填充数组时,视图标题将更新。当我在viewdidupdate中包含以上代码时,该数组确实已填充。我必须将其移至didupdatelocation方法,因为当视图加载到viewDidLoad方法中时,应用程序将没有位置信息。

The title of the view updates when location is found but the array doesn't populate. The array did populate before when I had the above code in the viewdidupdate. I had to move it to the didupdatelocation method because the application won't have the location info when the view loads in the viewDidLoad method.

推荐答案

您的表格视图不知道您有新数据。因此,一旦有了新数据,就需要告诉表视图重新加载:

Your table view doesn't know you have new data. So, once you have the new data, you need to tell your table view to reload:

[myTableView reloadData];

这篇关于在iPhone SDK上等待CLLocationManagerDelegate的didUpdateToLocation方法时,不会填充UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆