2012-08-14 169 views
0
[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(requestAddressUpdatedNotification:) 
              name:MTAddressUpdatedNotification 
              object:nil]; 

任何人都可以告诉我如果我在程序中写这段代码会发生什么?这段代码是什么意思?

何时将调用方法requestAddressUpdatedNotification

+0

你可能想看看[观察者模式](http://en.wikipedia.org/wiki/Observer_pattern) – 2012-08-14 08:54:59

回答

4

代码通知默认NSNotificationCenterMTAddressUpdatedNotification NSNotification发生时通知对象(self),并触发其必须在相同的类中定义(内@implementation…@endrequestAddressUpdatedNotification:方法。

+0

所以你的意思是,如果MTAddressUpdatedNotification发生,requestAddressUpdatedNotification将被调用? – generalzyq 2012-08-14 08:46:25

+0

是的,当MTAddressUpdatedNotification发布时,您的requestAddressUpdatedNotification:将被触发,或以Objective-C的说法“接收消息”。 – 2012-08-14 08:50:18

+0

非常感谢!〜 – generalzyq 2012-08-14 09:09:56