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

注意:注册通知和接收通知的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];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容