美文网首页
通知简单使用

通知简单使用

作者: 叶俊谋先生 | 来源:发表于2016-07-28 13:05 被阅读0次

    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];

    }

    相关文章

      网友评论

          本文标题:通知简单使用

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