iOS开发通知那些事

来源:互联网 发布:淘宝联盟怎么赚取佣金 编辑:程序博客网 时间:2024/05/22 22:00
   通知 是在跳转控制器之间常用的传值代理方式,除了代理模式,通知更方便、便捷.    
   1.//注册通知

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

   2.//通知方法

   - (void)change:(NSNotification *)notifi{
    
   }

   3.//移除通知 removeObserver:是删除通知中心保存的调度表一个观察者的所有入口

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

  4.//发送通知

    [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationCenterLogin object:nil userInfo:nil];

总结:一个简单的通知就ok了。如果通知要传参数,可以用通知的userInfo。



0 0