iphone - 在重大位置更改时重新加载/刷新 View Controller (来自应用程序委托(delegate))

标签 iphone ios objective-c xcode

我正在尝试使用重要位置更改来刷新我的 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/

相关文章:

ios - 我是否需要拥有 Apple 开发者帐户才能实现与 Game Center 的交互?

iphone - 在 UITableView 中延迟加载图像

objective-c - 创建多条画线

iphone - UITableView - 扩展单元格

ios - 查看不添加到 UITableViewCell

iphone - 由于太多未处理的消息而丢弃事件 0 的消息

iphone - 包含框架时链接器错误?

ios - Swift:如何声明采用可变/var 参数的函数签名?

objective-c - 如何通过错误代码识别 UIWebView 错误?

iphone - 比较 UIImage 的两种方法显示不同的结果。该相信哪一个呢?