所以我有一个方法:
-(void)didLoginWithAccount(MyAccount *)account我向这个方法添加了一个观察者,如下所示
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didLoginWithAccount:)];我的问题是,当我发布通知时,我如何传递一个MyAccount对象?
发布于 2013-04-06 01:52:48
当您收到通知回调时,将传递通知对象,而不是显式传递对象。
第1步,注册:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didLoginWithAccount:) name:@"MyCustomNotification" object:nil];第2步,发布:
[[NSNotificationCenter defaultCenter] postNotificationName:@"MyCustomNotification" object:myAccount]; 第三步,接收:
- (void)didLoginWithAccount:(NSNotification *)notification {
MyAccount *myAccount = (MyAccount *)[notification object];
}https://stackoverflow.com/questions/15840195
复制相似问题