ios 在显着位置更改时重新加载/刷新视图控制器(来自 App Delegate)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15063489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reload/Refresh View Controller on Significant Location Change (from App Delegate)
提问by Brandon
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!
我正在尝试使用更改的重要位置来刷新我的视图。位置管理器在我的应用程序委托中,我试图使用 NSNotificationCenter 告诉视图控制器在用户更改位置时刷新。我不确定如何刷新以刷新视图。我目前设置如下。我做了一个“视图控制器(刷新视图)”块,我认为刷新的代码会发生。有谁知道如何使这项工作?谢谢!
App Delegate (listen for significant location changes):
App Delegate(监听重要的位置变化):
- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation
*)newLocation fromLocation:(CLLocation *)oldLocation {
[[NSNotificationCenter defaultCenter] postNotificationName:@"refreshView" object:nil];
}
View Controller (Listen to NSNotificationCenter):
视图控制器(听 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
}
回答by Sudesh Kumar
-(void)refreshView:(NSNotification *) notification {
[self viewDidLoad];
[self viewWillAppear]; // If viewWillAppear also contains code
}