这里就是你要做的:
从课堂上发的消息,发布类似通知:
[[NSNotificationCenter defaultCenter] postNotificationName: @"YOUR_NOTIFICATION_NAME" object: anyobjectyouwanttosendalong(can be nil)];
在你想贴的时候要通知的通知的视图控制器:
在viewDidLoad中做到:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(METHOD_YOU_WANT_TO_INVOKE_ON_NOTIFICATION_RECEIVED) name:@"YOUR_NOTIFICATION_NAME" object:sameasbefore/nil];
重要!不要忘记这一点在你的viewDidUnload():
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"YOUR_NOTIFICATION_NAME" object:sameasbefore/nil];
我不是很肯定与通知相关联的对象,但你可以看看,最多here
注意:当只有一个对象,通知另一一个,你最好使用协议:)但在这种情况下,因为有多个视图控制器聆听,使用通知
来源
2011-04-25 23:40:41
Sid
真棒我会玩这个:)我来自PocketPC开发,所以我完全向后嘿 – 2011-04-25 23:40:36