• 控制器之间的通信(传值方法)以及多次调用通信


    //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;
  • 相关阅读:
    结构体后面不加 ; 的后果。
    swap的两种错误写法
    rewind和fseek作用分析
    16个get函数的用法。
    枚举的简单使用。
    小知识点
    网线头的做法
    内存和寄存器
    linux下service mongod start启动报错
    appium上下文切换、webview调试以及chromedriver/键盘等报错问题解决
  • 原文地址:https://www.cnblogs.com/hw140430/p/3750569.html
Copyright © 2020-2023  润新知