0

CLLocationManager在应用程序中。所以我需要的是知道用户是否允许或拒绝当前位置的方法。根据用户回答 TableController 以特定方式在表中添加值。我尝试过[sightsTableView reloadData];
- (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;
 }

更新:实际上重新加载没有问题。我知道刷新表视图有问题。如果我开始滚动表格单元格显示新值。

第二次更新 现在表正在刷新。问题是我如何打电话UITableView。我用过[tempTableView reloadData];,但它对我不起作用,所以我尝试使用它[self.tableView reloadData];,现在它正在重新加载值并刷新它。

4

2 回答 2

0
locmanager = [[CLLocationManager alloc] init];
[locmanager setDelegate:self];
[locmanager setDesiredAccuracy:kCLLocationAccuracyBest];

if (!locmanager.locationServicesEnabled)
{
    [contentView setText:@"Location Services Are Not Enabled"];
    return;
}
于 2010-10-02T19:26:48.307 回答
0

您是否设置了断点并确认重新加载表视图数据的代码实际上正在运行?如果它没有运行,您确定您已将视图控制器设置为 CLLocationManager 的委托吗?

要检测用户是否拒绝让您获取他们的当前位置,您可以实现 locationManager:didFailWithError: 并查看错误代码是否为 kCLErrorDenied。

更新

我的问题很大一部分是这些行

BOOL locationError = NO;
BOOL locationError = YES;

那是创建一个仅存在于该方法中的新变量,而不是设置存在于您的类中的 locationError 变量。您要么想要删除,BOOL要么执行 self.locationError = NO;

于 2010-10-02T20:38:44.730 回答