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

Iphone 重大位置更改时重新加载/刷新视图控制器(来自应用程序代理),iphone,ios,objective-c,xcode,Iphone,Ios,Objective C,Xcode,我正在尝试使用更改的重要位置刷新视图。位置管理器位于我的应用程序代理中,我正在尝试使用NSNotificationCenter通知视图控制器在用户更改位置时刷新。我不确定如何刷新以刷新视图。我目前有如下设置。我制作了一个“视图控制器(刷新视图)”块,我认为刷新的代码将在其中发生。有人知道怎么做吗?谢谢大家! 应用程序代理(监听重要位置更改): - (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CL

我正在尝试使用更改的重要位置刷新视图。位置管理器位于我的应用程序代理中,我正在尝试使用NSNotificationCenter通知视图控制器在用户更改位置时刷新。我不确定如何刷新以刷新视图。我目前有如下设置。我制作了一个“视图控制器(刷新视图)”块,我认为刷新的代码将在其中发生。有人知道怎么做吗?谢谢大家!

应用程序代理(监听重要位置更改):

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

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

}
- (void)viewDidLoad {

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

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

//CODE TO REFRESH THE VIEW HERE

}
查看控制器(收听NSNotificationCenter):

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

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

}
- (void)viewDidLoad {

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

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

//CODE TO REFRESH THE VIEW HERE

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

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

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

}
- (void)viewDidLoad {

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

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

//CODE TO REFRESH THE VIEW HERE

}

UIViewController*根=_window.rootViewController;UINavigationController*navController=(UINavigationController*)根目录;YourViewController*mycontroller=(YourViewController*)[[navController-ViewController]对象索引:0];[mycontroller重新加载输入视图];谢谢你,苏迪斯。所以我可以再次调用[self-viewDidLoad]?是的,你可以:)但是要小心,如果在viewDidLoad中创建了任何变量,那么它将创建另一个实例并可以增加内存。因此,在创建任何变量之前,如果不使用ARC,请释放旧的一个。明白了-使用ARC应该可以吗?是的?-1这需要修复。将viewDidLoad中的内容移到外部并调用该方法。调用viewDidLoad应仅在以下情况下发生。。。视图实际加载