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;
  • 相关阅读:
    轻配置 Vim
    PHP 使用 wkhtmltopdf/image 把HTML页面转换成 PDF/image 文件
    使用 Mailgun 实现 带附件的Email 发送功能
    LinkedIn 第三方登录(JavaScript SDK)
    react学习2
    前端面试题
    react学习
    前端面试-字符串-逆序-间隔
    前端文件上传相关知识
    js原型prototype问题
  • 原文地址:https://www.cnblogs.com/hw140430/p/3750569.html
Copyright © 2011-2022 走看看