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

2018-04-25  本文已影响0人  Cocojiang

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

}

上一篇 下一篇

猜你喜欢

热点阅读