1

我正在尝试用一组单元格填充 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;

找到位置但未填充数组时,视图的标题会更新。当我在 viewdidupdate 中有上述代码时,该数组确实填充了。我不得不将它移动到 didupdatelocation 方法,因为当视图在 viewDidLoad 方法中加载时,应用程序将没有位置信息。

4

1 回答 1

2

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];
于 2009-04-02T00:30:09.800 回答