Cat*_*thy 5 objective-c nsnotifications
我创建了一个程序来通过NSNotification发送和接收事件.现在我需要与事件一起发送数据.任何人都可以建议我如何在Objective-C编码中做到这一点?
有两种方法 - 一种,你可以通过任何一个对象通过 - 看看
+ (id)notificationWithName:(NSString *)aName object:(id)anObject
Run Code Online (Sandbox Code Playgroud)
第二件事是,你也可以传递一个包含任意数量对象的可选字典,你只需要让双方都同意用于存储和检索对象的键.那个电话是:
+ (id)notificationWithName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)userInfo
Run Code Online (Sandbox Code Playgroud)
在任一调用中,您始终可以为anObject或userInfo传递nil.
直接发送通知的示例调用(如果您不想,则不必首先构造通知):
[[NSNotifcationCenter defaultCenter] postNotificationName:@"MyNotification" object:myObjectToSend];
Run Code Online (Sandbox Code Playgroud)
还添加了userInfo的调用的变体,就像通知构造一样.
| 归档时间: |
|
| 查看次数: |
1444 次 |
| 最近记录: |