Dav*_*ong 15
委派是单个消息传递协议.如果要向更改的多个对象发送消息,则需要使用NSNotifications.
您可以使用通知中心传递对象,如下所示:
NSDictionary *userInfo = @{@"myObject" : customObject};
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:@"myNotificationString" object:self userInfo:userInfo];
Run Code Online (Sandbox Code Playgroud)
想要收听通知时
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myCustomObserver:)name:@"myNotificationString" object:nil];
Run Code Online (Sandbox Code Playgroud)
并设置选择器
-(void)myCustomObserver:(NSNotification *)notification{
CustomObject* customObject = notification.userInfo[@"myObject"];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6082 次 |
| 最近记录: |