Delegates and Notifications
An object that has made itself the delegate of a standard Cocoa object is probably interested in receiving notifications from that object as well. For example, if you have implemented a delegate to handle the windowShouldClose: delegate method for a window, that same object is likely to be interested in the NSWindowDidResizeNotification from that same window.
If a standard Cocoa object has a delegate and posts notifications, it is automatically registered as an observer for the methods the object implements. If you are implementing such a delegate, how would you know what to call the method?
The naming convention is simple: Start with the name of the notification. Remove NS from the beginning, and make the first letter lowercase. Remove Notification from the end. Add a colon. For example, to be notified that the window has posted anNSWindowDidResizeNotification, the delegate would implement the following method:
- (void)windowDidResize:(NSNotification *)aNotification
This method will be called automatically after the window resizes. You can also find this method listed in the documentation and header files for the class NSWindow.
1968

被折叠的 条评论
为什么被折叠?



