0

I have CLLocationManager in app. So what i need is method to know did a user allow or decline current location. According users answer TableController adding value in table in specific way. I tried to [sightsTableView reloadData]; in
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation but after i choose allow or decline tableview is not reloading. I checked Apple's CLLocation reference and couldn't find something useful. UPD:here is codde sample.

 - (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;
 }

UPDATE: Actually there is no problem with reload. I got that i have problem with refresh table view. If i start to scroll table cell shows new value.

SECOND UPDATE Now the table is refreshing. The issue was how i called UITableView. I used [tempTableView reloadData];, but it's didn't work for me, so i tried to use this [self.tableView reloadData]; and now it's RELOADING values and REFRESHING it.

sherilyn
  • 374
  • 2
  • 10

2 Answers2

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

if (!locmanager.locationServicesEnabled)
{
    [contentView setText:@"Location Services Are Not Enabled"];
    return;
}
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80
0

Have you set a breakpoint and confirmed that the code to reload the table view's data is actually being run? If it isn't being run, are you sure that you've set your view controller as the CLLocationManager's delegate?

To detect if the user declined to allow you to get their current location, you can implement locationManager:didFailWithError: and see if the error's code is kCLErrorDenied.

Update

I big part of your problem is these lines

BOOL locationError = NO;
BOOL locationError = YES;

That's creating a new variable that just lives in that method, instead of setting the locationError variable that lives in your class. You either want to remove the BOOL or do self.locationError = NO;

Jacques
  • 6,050
  • 1
  • 31
  • 24
  • Yes i set a breakpoint and it's works. I also using `didFailWithError` method. See, i using `BOOL locationError = YES;` and do reload after that `[tempTableView reloadData];` in `didFailWithError`. And next where app using `locationError` is `cellForRowAtIndexPath`. `if(self.locationError == NO){ cell.detailTextLabel.text = @"1"; }`. So i think after i reload table view with `locationError == NO` it's have to work. – sherilyn Oct 02 '10 at 20:52
  • @sherilyn, can you post your code for didFailWithError and cellForRowAtIndexPath? I'm not quite following some of the stuff you just said, so it might be a lot easier to figure it out if I can see some code. – Jacques Oct 02 '10 at 21:11
  • it doesn't change anything. table view still not reloaded ( – sherilyn Oct 02 '10 at 21:48
  • app is loading with TableView then pop-up location alert.doesn't matter what i choose - table view still not reloaded, but should . – sherilyn Oct 02 '10 at 21:54