我正在尝试使用一组单元格填充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方法中加载时,应用程序将没有位置信息。
答案 0 :(得分:2)
您的表格视图不知道您有新数据。因此,一旦获得了新数据,就需要告诉表视图重新加载:
[myTableView reloadData];