我刚学习ios编程,更新了最新的XCode5之后,创建一个简单的单ViewController工程后。直接在界面中实现一些功能。但是如果想在另一个类,或者另一个UIViewController类中刷新这个UIViewController界面怎么实现。在可视化的界面中直接关联类。然后就实现了,没看见有对象什么的,不知道怎么调用啊。求高手指点,在线等啊!
------解决方案--------------------
这是观察者模式的一种体现,当一个对象发生改变时去通知它的所有订阅者。
在iOS中,你可以使用“通知中心” NSNotificationCenter来实现
在需要接收通知的类中添加观察者
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedNotif:) name:@"ReloadView" object:nil];
-(void)receivedNotif:(NSNotification *)notification {
///////to do.....
}
在需要发送通知的类中
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReloadView" object:nil];
注册发送通知及接收通知是通过 notificationName来建立的关联。