在iPhone SDK上等待CLLocationManagerDelegate的didUpdateToLocation方法时,UITableView不会填充
我正在尝试用单元格数组填充UITableview。 我通常从viewDidLoad方法做到这一点,但这次我想根据位置填充数组。 以下是我的界面的第一行:
@interface RootViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource, CLLocationManagerDelegate> {
在实现文件中,viewDidLoad方法如下所示:
- (void)viewDidLoad { // for location self.locationManager = [[CLLocationManager alloc] init]; [locationManager startUpdatingLocation]; locationManager.delegate = self; locationManager.distanceFilter = kCLDistanceFilterNone; locationManager.desiredAccuracy = kCLLocationAccuracyBest; [super viewDidLoad]; }
我在didUpdateToLocation方法中填充单元格数组:
self.title = @"Open Buildings"; NSMutableArray *buildingArray = [[NSMutableArray alloc] initWithObjects:building1, self.controllers = array;
视图的标题在find位置时更新,但数组不填充。 在viewdidupdate中有上面的代码之前,数组填充了。 我不得不将它移动到didupdatelocation方法,因为当视图加载到viewDidLoad方法中时,应用程序将没有位置信息。
你的表格视图不知道你有新的数据。 所以,一旦你有新的数据,你需要告诉你的表视图重新加载:
[myTableView reloadData];