Delegates and Notifications

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值