iOS 通知传值

下面是来客网 jb51.cc 通过网络收集整理的代码片段。

来客网小编现在分享给大家,也给大家做个参考。

//设置通知   
 //获取通知中心
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    //通知中心 发送广播
    /*
     第一个参数就是通知的名字 第二个参数 谁发送的通知
        第三个参数 通知的内容
     
     这个方法内部会创建一个通知对象
     */
    //把通知的内容放入字典中
    NSDictionary *dict = @{@"status": @"123"};
    
    //自定义的通知
    [nc postNotificationName:kNotificationChangeStatus object:self userInfo:dict];


/***********************************************************************************/
//接收通知
//在viewDidLoad方法中注册观察者
//提前创建观察者
        NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
        //注册观察者
        //接收任意对象发送的kNotificationChangeStatus通知
        [nc addObserver:self selector:@selector(changeLabelText:) name:kNotificationChangeStatus object:nil];


//实现接收通知方法
- (void)changeLabelText:(NSNotification*)nf{
    //获取通知的内容
    NSDictionary *dict = nf.userInfo;
    
    NSString * isOn = dict[@"status"];
     NSLog(@"%@",isOn);

}
//最后别忘了  
//删除观察者
- (void)dealloc{
    //删除观察者
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kNotificationChangeStatus object:nil];
}

以上是来客网(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。

以上是来客网为你收集整理的iOS 通知传值全部内容,希望文章能够帮你解决iOS 通知传值所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。