zoukankan      html  css  js  c++  java
  • 传值

    通知中心传值

    头文件
    //  Common.h
    //  通知中心传值
    //
    
    #ifndef Common_h
    #define Common_h
    #define NotificationName @"changeValur"
    
    #endif /* Common_h */
    
    ------------------------------------------------------------------------------
    //  ViewController.m
    //  通知中心传值
    //
    
    #import "ViewController.h"
    #import "Common.h"
    @interface ViewController ()
    @property (weak, nonatomic) IBOutlet UITextField *text1;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // 通知的接受者(接收到通知后响应事件的对象) 接受到通知后响应的事件  当前通知的名称 当前通知的发送者(一般为nil)
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeValueText:) name:NotificationName object:nil];
        // Do any additional setup after loading the view, typically from a nib.
    }
    -(void)changeValueText:(NSNotification *)nsnotification{
        //获取通知发送者的发送的信息
        NSDictionary *dict = nsnotification.userInfo;
        //键值
        _text1.text = dict[@"value"];
    }
    -(void)dealloc{
        //移除通知
        [[NSNotificationCenter defaultCenter]removeObserver:self name:NotificationName object:nil];
    }
    
    --------------------------------------------------------------------------------
    //  ChangeViewController.m
    //  通知中心传值
    //
    
    #import "ChangeViewController.h"
    #import "Common.h"
    @interface ChangeViewController ()
    @property (weak, nonatomic) IBOutlet UITextField *text2;
    
    @end
    
    @implementation ChangeViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
    }
    - (IBAction)back:(UIButton *)sender {
      //发送通知的名称 发送者(一般为nil) 发送内容 [[NSNotificationCenter defaultCenter] postNotificationName:
    object:nil userInfo:@{@"value":_text2.text}]; [self dismissViewControllerAnimated:YES completion:nil]; }

     代理传值

  • 相关阅读:
    P1265 公路修建 最小生成树
    P1991 无线通讯网 最小生成树
    Stock Chase 拓扑
    Rank of Tetris 拓扑排序+并查集
    P1169 [ZJOI2007]棋盘制作 DP悬线法
    P4147 玉蟾宫 二维DP 悬线法
    P1341 无序字母对 欧拉回路
    P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm 记忆化搜索dfs
    BSTestRunner插件的用法.py
    Selenium
  • 原文地址:https://www.cnblogs.com/longiang7510/p/5362433.html
Copyright © 2011-2022 走看看