Mat*_*art 3 notifications object objective-c sender
我似乎无法找到如何发布与对象和发件人的通知.
我可以发布带有姓名,发件人和用户信息的通知.看到:
- (void)postNotificationName:(NSString *)notificationName
object:(id)notificationSender
userInfo:(NSDictionary *)userInfo
Run Code Online (Sandbox Code Playgroud)
我可以使用对象发布NSNotification,但不能将发件人链接到它:
NSNotification *notification = [NSNotification notificationWithName:name
object:someObject];
[[NSNotificationCenter defaultCenter] postNotification:notification];
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我如何使用(a)对象和(b)发件人参考发布通知?
Joo*_*ost 16
在你提出的两种方法中,object变量代表通知的发送者,它可以是你真正想要的任何东西.要通过通知提供其他对象,您可以将包含对象的字典传递给userInfo.
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
someObject, @"someObject",
anotherObject, @"anotherObject", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:name
object:sender
userInfo:options];
Run Code Online (Sandbox Code Playgroud)