Iphone 如果用户允许或拒绝获取当前位置,请重新加载TableView数据

Iphone 如果用户允许或拒绝获取当前位置,请重新加载TableView数据,iphone,tableview,cllocationmanager,Iphone,Tableview,Cllocationmanager,我在应用程序中有CLLocationManager。所以我需要的是一个方法,知道用户是否允许或拒绝当前位置。根据用户的回答,TableController以特定的方式在表中添加值。我试图[sightsTableView reloadData]在 -(void)locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLo

我在应用程序中有
CLLocationManager
。所以我需要的是一个方法,知道用户是否允许或拒绝当前位置。根据用户的回答,TableController以特定的方式在表中添加值。我试图
[sightsTableView reloadData]
-(void)locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation
但在我选择允许或拒绝后,tableview不会重新加载。我查看了苹果的位置参考,没有找到有用的东西。 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
。我使用了
[试探性视图重载数据],但它对我不起作用,所以我尝试使用这个
[self.tableView reloadData]现在它正在重新加载值并刷新它。

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

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

if (!locmanager.locationServicesEnabled)
{
    [contentView setText:@"Location Services Are Not Enabled"];
    return;
}
要检测用户是否拒绝允许您获取其当前位置,您可以实现locationManager:didFailWithError:并查看错误代码是否为kCLErrorDenied

更新

我认为你的问题很大一部分是这些线路

BOOL locationError = NO;
BOOL locationError = YES;

这就是创建一个新的变量,它只存在于该方法中,而不是设置存在于类中的locationError变量。要删除
BOOL
或执行self.locationError=NO;我确实试过这个方法。但是TableView的加载速度比“location enabler”的加载速度更快。所以我需要在用户回答后重新加载tebleview。这可能也与您是在模拟器中运行还是在实际设备上运行有关?是的,我设置了一个断点,它正常工作。我还使用了
didFailWithError
方法。请参阅,i使用
BOOL locationError=YES
并在此之后重新加载
[TestableView reloadData]
didFailWithError
中。下一个使用
locationError
的应用程序是
cellforrowatinexpath
if(self.locationError==NO){cell.detailtextlab.text=@“1”}
。所以我想在我用
locationError==NO
重新加载表视图之后,它必须工作。@sherilyn,你能发布你的didFailWithError和cellforrowatinexpath的代码吗?我没有完全理解你刚才说的一些东西,所以如果我能看到一些代码,可能会更容易理解。它不会改变任何东西。表视图仍然没有重新加载(应用程序正在加载TableView,然后会弹出位置警报。无论我选择什么-表视图仍然没有重新加载,但应该加载。