UITableView doesn't populate when waiting for CLLocationManagerDelegate 's didUpdateToLocation method on iPhone SDK

房东的猫 提交于 2020-01-15 14:09:25

问题


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> {

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];
}

I populate the array of cells in the didUpdateToLocation method:

    self.title = @"Open Buildings";

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

self.controllers = array;

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.


回答1:


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];


来源:https://stackoverflow.com/questions/707766/uitableview-doesnt-populate-when-waiting-for-cllocationmanagerdelegate-s-didup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!