zoukankan      html  css  js  c++  java
  • iOS传值之通知传值(三)

    输入所要发送的信息 ,同时将label的值通过button方法调用传递,

    - (IBAction)buttonClick:(id)sender {

        //添加 字典,将label的值通过key值设置传递

        NSDictionary *dict =[[NSDictionary alloc]initWithObjectsAndKeys:self.textFieldOne.text,@"textOne",self.textFieldTwo.text,@"textTwo", nil];

        //创建通知

        NSNotification *notification =[NSNotification notificationWithName:@"tongzhi" object:niluserInfo:dict];

        //通过通知中心发送通知

        [[NSNotificationCenter defaultCenter] postNotification:notification];

        [self.navigationController popViewControllerAnimated:YES];

    }

    在发送通知后,在所要接收的控制器中注册通知监听者,将通知发送的信息接收

    - (void)viewDidLoad {

        [super viewDidLoad];

        //注册通知

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

    }

    - (void)tongzhi:(NSNotification *)text{

        NSLog(@"%@",text.userInfo[@"textOne"]);

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

    }

  • 相关阅读:
    并不对劲的辛普森积分
    并不对劲的概率与期望
    并不对劲的cdq分治解三维偏序
    68.机器人的运动范围
    67.矩阵中的路径
    66.滑动窗口最大值
    65.数据流的中位数
    64.二叉搜索树的第K个节点
    63.序列化二叉树
    62.把二叉树打印成多行
  • 原文地址:https://www.cnblogs.com/Jordandan/p/5099047.html
Copyright © 2011-2022 走看看