简体   繁体   中英

Reload/Refresh View Controller on Significant Location Change (from App Delegate)

I am trying to have my view refreshed using significant location changed. The location manager is in my app delegate, and I am trying to use the NSNotificationCenter to tell the view controller to refresh if the user changes locations. I am not sure how to refresh to refresh the view. I currently have it set up like below. I made a "View Controller (refresh the view)" block where I think the code for the refresh would take place. Anyone know how to make this work? Thank you!

App Delegate (listen for significant location changes):

- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation  
*)newLocation fromLocation:(CLLocation *)oldLocation {

[[NSNotificationCenter defaultCenter] postNotificationName:@"refreshView" object:nil];

}

View Controller (Listen to NSNotificationCenter):

- (void)viewDidLoad {

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshView:) 
name:@"refreshView" object:nil];

}

View Controller (refresh the view):

-(void)refreshView:(NSNotification *) notification {

//CODE TO REFRESH THE VIEW HERE

}
-(void)refreshView:(NSNotification *) notification {

[self viewDidLoad];
[self viewWillAppear]; // If viewWillAppear also contains code

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM