我正在尝试使用重要位置更改来刷新我的 View 。位置管理器位于我的应用程序委托(delegate)中,我尝试使用 NSNotificationCenter 告诉 View Controller 在用户更改位置时刷新。我不知道如何刷新来刷新 View 。我目前的设置如下。我制作了一个“ View Controller (刷新 View )” block ,我认为刷新的代码将在其中发生。有人知道如何进行这项工作吗?谢谢!
应用程序代理(监听重大位置变化):
- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation
*)newLocation fromLocation:(CLLocation *)oldLocation {
[[NSNotificationCenter defaultCenter] postNotificationName:@"refreshView" object:nil];
}
View Controller (监听 NSNotificationCenter):
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshView:)
name:@"refreshView" object:nil];
}
View Controller (刷新 View ):
-(void)refreshView:(NSNotification *) notification {
//CODE TO REFRESH THE VIEW HERE
}
最佳答案
-(void)refreshView:(NSNotification *) notification {
[self viewDidLoad];
[self viewWillAppear]; // If viewWillAppear also contains code
}
关于iphone - 在重大位置更改时重新加载/刷新 View Controller (来自应用程序委托(delegate)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15063489/