通知中心

    //通知中心没有依赖性, 只要是两个页面存在

    //通知中心的使用

    //1. 获取通知中心, 注册一个观察者和事件

 //这是一个单例类

    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

    

    //再通知中心中, 添加一个观察者和观察事件

    //参数1: 负责相应事件的观察对象

    //参数2: 一旦收到消息, 观察者要执行的方法

    //参数3: 观察者要监听的事件

    //参数4: 可以限定消息发出者

    [center addObserver:self selector:@selector(receiveNotification:) name:@"上厕所" object:nil];

//收到通知中心的消息时, 观察者(self)要调用的方法

- (void)receiveNotification:(NSNotification *)noti

{

    NSLog(@"%@", noti.object);

    self.view.backgroundColor = [UIColor blackColor];

}












- (void)buttonAction:(UIButton *)button

{

    //通知中心的使用

    //发送一个消息

    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

    //参数1: 发送消息的事件名

    //参数2: 可以使用这个参数, 传递一个对象给观察者

    //参数3: 一些消息的参数信息(系统用的比较多)

    [center postNotificationName:@"上厕所" object:@"香皂" userInfo:nil];

    

    [self.navigationController popToRootViewControllerAnimated:YES];

    

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值