通知简单使用

1.创建通知,通过通知中心发送通知(比如你在a控制器想让b控制器做点什么的时候,并且控制器没什么关系的情况下)

NSNotification *Notification =[NSNotification notificationWithName:@"tongzhi" object:nil userInfo:nil];

[[NSNotificationCenter defaultCenter] postNotification:Notification];

2.注册通知

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

2.1绑定通知实现的方法

- (void)tongzhi{

NSLog(@"-----接收到通知------");

}

3.发送通知页面一定要在页面销毁是同时销毁通知

-(void)dealloc

{

[[NSNotificationCenter defaultCenter] removeObserver:self name:@"tongzhi" object:nil];

}

你可能感兴趣的:(通知简单使用)