重大位置更改时重新加载/刷新视图控制器(来自应用程序代理)



我正试图通过更改重要位置来刷新视图。位置管理器在我的应用程序委派中,我正试图使用NSNotificationCenter来告诉视图控制器,如果用户更改位置,请刷新。我不知道如何刷新视图。我目前的设置如下。我制作了一个"视图控制器(刷新视图("块,我认为刷新的代码会在那里发生。有人知道怎么做吗?非常感谢。

应用程序代理(监听显著的位置变化(:

- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation  
*)newLocation fromLocation:(CLLocation *)oldLocation {
[[NSNotificationCenter defaultCenter] postNotificationName:@"refreshView" object:nil];
}

查看控制器(收听NSNotificationCenter(:

- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshView:) 
name:@"refreshView" object:nil];
}

视图控制器(刷新视图(:

-(void)refreshView:(NSNotification *) notification {
//CODE TO REFRESH THE VIEW HERE
}
-(void)refreshView:(NSNotification *) notification {
[self viewDidLoad];
[self viewWillAppear]; // If viewWillAppear also contains code
}

最新更新