【发布时间】:2010-10-02 18:39:34
【问题描述】:
我在应用中有CLLocationManager。所以我需要的是知道用户是否允许或拒绝当前位置的方法。根据用户回答 TableController 以特定方式在表中添加值。我尝试[sightsTableView reloadData]; in- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 但在我选择允许或拒绝后,tableview 不会重新加载。我检查了 Apple 的 CLLocation 参考,找不到有用的东西。
UPD:这里是代码示例。
- (void)viewDidLoad {
super viewDidLoad];
[[self locationManager] startUpdatingLocation];
[tempTableView reloadData];
}
- (CLLocationManager *)locationManager {
if (locationManager != nil) {
return locationManager;
}
locationManager = [[CLLocationManager alloc] init];
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
[locationManager setDelegate:self];
return locationManager;
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
NSLog(@"User allow get location");
self.locationError = NO;
[tempTableView reloadData];
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error {
NSLog(@"User declined get location");
self.locationError = YES;
[tempTableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
.... some big code about a sells )...
cell.textLabel.text = array.title;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if(self.locationError == NO){
cell.detailTextLabel.text = @"!";
}
return cell;
}
更新: 实际上reload没有问题。我知道刷新表视图有问题。如果我开始滚动表格单元格显示新值。
第二次更新
现在桌子焕然一新。问题是我如何称呼UITableView。我使用了[tempTableView reloadData];,但它对我不起作用,所以我尝试使用这个[self.tableView reloadData];,现在它正在重新加载值并刷新它。
【问题讨论】:
标签: iphone tableview cllocationmanager