美文网首页
iOS 开发中NSNotification(通知)的使用

iOS 开发中NSNotification(通知)的使用

作者: 谁拿浮生伴我一世流年 | 来源:发表于2016-05-24 09:56 被阅读2099次

注意:注册通知和接收通知的Name必须相同(即notificationWithName:@"buttonLoseResponse"&&addObserver: selector: name:@"buttonLoseResponse")

一.在要发出通知的界面注册通知并发送通知:

1.注册通知:

NSNotification *LoseResponse = [NSNotification notificationWithName:@"buttonLoseResponse" object:nil];

2.发送通知:

[[NSNotificationCenter defaultCenter] postNotification:LoseResponse];

二.要接受通知的界面

1.接收通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(walkVCClick:) name:@"buttonLoseResponse" object:nil];

2.实现方法:

- (void)walkVCClick:(NSNotification *)noti

{


}

3.移除通知:

-(void)dealloc {

[[NSNotificationCenter defaultCenter] removeObserver:self];

}

相关文章

网友评论

      本文标题:iOS 开发中NSNotification(通知)的使用

      本文链接:https://www.haomeiwen.com/subject/jlkzrttx.html