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;
  • 相关阅读:
    IDEA tomcat热部署方法及乱码问题解决
    访问WEB-INF下JSP资源的几种方式(转)
    SpringMVC 静态资源处理
    SpringMVC中的拦截器
    SpringMVC中的异常处理
    SpringMVC实现文件上传
    IDEA 热部署
    响应数据和结果视图
    SpringMVC中的常用注解
    js获取当前根目录的方法
  • 原文地址:https://www.cnblogs.com/hw140430/p/3750569.html
Copyright © 2011-2022 走看看