问题描述
我正在尝试用一个单元格数组填充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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!