Non-retaining array for delegates

后端 未结 10 1392
感动是毒
感动是毒 2020-11-29 18:41

In a Cocoa Touch project, I need a specific class to have not only a single delegate object, but many of them.

It looks like I should create an NSArray for these del

10条回答
  •  庸人自扰
    2020-11-29 19:28

    You do not want to do this! Cocoa Touch have several concepts for sending events, you should use the proper concept for each case.

    1. Target-action: For UI controls, such as button presses. One sender, zero or more receivers.
    2. Delegates: For one sender and one receiver only.
    3. Notification: For one sender, and zero or more receivers.
    4. KVO: More fine grained that notifications.

    What you should do is to look into how to use NSNotificationCenter class. This is the proper way to send a notification that have more than one receiver.

提交回复
热议问题