zoukankan      html  css  js  c++  java
  • 控制器之间的通信(传值方法)以及多次调用通信

    //1.调用通知进行回调方法

    //
    A控制器中 - (void)toDo{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(test) name:@"testName" object:nil]; } //当B控制器中的viewDidLoad方法调用时,此方法会被触发 -(void)test{ NSLog(@"已回调");
       //先移除通知,再重新注册(否则连续多次调用通信时,此方法会调用多次)
       [[NSNotificationCenter defaultCenter]removeObserver:self name:@"testName" object:nil];    
      [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(test) name:@"testName" object:nil];
    }
    //===================== //B控制器中 - (void)viewDidLoad{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(test) name:@"testName" object:nil]; }
    //2.通过AppDelegate传值取值

    //
    A控制器
    通过AppDelegate传值(在当前控制器中导入AppDelegate.h)
    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; appDelegate.address = _address; //B控制器
    通过AppDelegate取值(在当前控制器中导入AppDelegate.h) AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; _address = appDelegate.address;
  • 相关阅读:
    python base64加密文本内容(1)
    python 翻译爬虫
    json为txt文本加密
    python json
    repr()函数
    linux 基本命令
    测试管理工具--禅道
    测试基础理论
    测试用例--场景法
    测试用例--测试大纲(提纲)法
  • 原文地址:https://www.cnblogs.com/hw140430/p/3750569.html
Copyright © 2011-2022 走看看