• 传值


    通知中心传值

    头文件
    //  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]; }

     代理传值

  • 相关阅读:
    无向图判断割点
    C
    连通图 求至少有给几个点信息才能传遍全图,至少添加几条边才能使全图联通
    线段树区间更新(set暴力)
    A
    辗转相除法(数学推理)
    Python List index()方法
    Python List extend()方法
    Python List count()方法
    Python List append()方法
  • 原文地址:https://www.cnblogs.com/longiang7510/p/5362433.html
Copyright © 2020-2023  润新知