iOS 页面跳转传值,属性传值,代理传值,代码块传值,单例传值,通知传值

有时候我们在页面跳转的时候回传递相应的参数,如,你想把在第一个页面的文本框里的内容显示在第二个文本框中,或者你又想把第二个文本框中的内容改变之后到第一个页面的文本框中,所有,这个时候我们就要用到页面跳转传值

1.属性传值(正向传值)



属性传值是正向传值,只可以从前面一个页面传递到第二个页面,不可以从第二个页面传递到第一个页面

2.代理传值(逆向传值)



代理传值是逆向传值

代理传值步骤

代理传值
适用于 反向传值
1.1 创建协议 及协议方法 在反向传值的页面(SecondViewController)中
1.2 创建协议类型的属性 在SecondViewController中创建属性id<postValueDelegate> delegate
1.3 调用属性 即delegate
在SecondViewController页面中 对象传值的方法中调用
[self.delegate postValue:self.textName.text];

1.4 在第一页 即显示修改过信息的页面
遵循协议 实现协议方法 指定代理对象(即 在页面传值参数的方法中为代理赋值)

具体代码如下

firstViewController.h

#import <UIKit/UIKit.h>
#import "secondViewController.h"
@interface firstViewController : UIViewController<postValueDeletage,UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;
@end

firstViewController.m

#import "firstViewController.h"

@interface firstViewController ()

@end

@implementation firstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor colorWithRed:0.565 green:1.000 blue:0.994 alpha:1.000];

    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    self.name1.delegate=self;
    self.name1.backgroundColor=[UIColor colorWithRed:0.905 green:0.903 blue:0.910 alpha:1.000];
    [self.view addSubview:self.name1];

    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(150, 200, 100, 100)];
    [self.btn setTitle:@"点击" forState:0];
    [self.btn addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
    self.btn.backgroundColor=[UIColor colorWithRed:0.210 green:0.257 blue:0.382 alpha:1.000];

    [self.view addSubview:self.btn];

}

-(void)postValue:(NSString *)str{

    self.name1.text=str;
}

-(void)next{
    secondViewController *second=[[secondViewController alloc]init];
    second.deletage=self;
    second.str=self.name1.text;
    [self presentViewController:second animated:YES completion:nil];

}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }

    return YES;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.name1 resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

secondViewController.h 第二个页面

#import <UIKit/UIKit.h>
@protocol postValueDeletage <NSObject>

-(void)postValue:(NSString *)str;

@end
@interface secondViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;
@property(nonatomic,strong)NSString *str;
@property(nonatomic,assign)id<postValueDeletage> deletage;
@end

secondViewController.m

#import "secondViewController.h"

@interface secondViewController ()

@end

@implementation secondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor colorWithRed:1.000 green:0.314 blue:0.659 alpha:1.000];

    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    self.name1.backgroundColor=[UIColor colorWithRed:0.905 green:0.903 blue:0.910 alpha:1.000];
    self.name1.text=self.str;
    [self.view addSubview:self.name1];
    self.name1.delegate=self;
    self.name1.text=self.str;

    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(150, 200, 100, 100)];
    [self.btn setTitle:@"上一页" forState:0];
    [self.btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    self.btn.backgroundColor=[UIColor colorWithRed:0.210 green:0.257 blue:0.382 alpha:1.000];

    [self.view addSubview:self.btn];

}
-(void)back{

    [self.deletage postValue:self.name1.text];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }
    return YES;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.name1 resignFirstResponder];

}

AppDelegate.h

#import <UIKit/UIKit.h>
#import "firstViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

AppDelegate.m文件

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    firstViewController *first=[[firstViewController alloc]init];
    self.window.rootViewController=first;

    return YES;
}

3.单例传值(双向传值)



首先创建一个单例类

AppStatus.h

#import <Foundation/Foundation.h>

@interface AppStatus : NSObject<NSCopying>
@property(nonatomic,copy)NSString *contextStr;
+(AppStatus *)shareInstance;
@end

AppStatus.m文件

#import "AppStatus.h"

@implementation AppStatus
static AppStatus *appstatus;
//单例方法
+(AppStatus *)shareInstance{
    if (appstatus==nil) {
        appstatus=[[AppStatus alloc]init];
    }

    return appstatus;
}
//单例方法 初始化
+(instancetype)allocWithZone:(struct _NSZone *)zone{
    if (appstatus==nil) {
        appstatus=[super allocWithZone:zone];
    }
    return appstatus;
}

//单例方法 复制
-(id)copyWithZone:(NSZone *)zone{

    return self;
}
@end

第一个页面

firstViewController.h

#import <UIKit/UIKit.h>
#import "sceondViewController.h"
#import "AppStatus.h"
@interface firstViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;
@end

firstViewController.m

#import "firstViewController.h"

@interface firstViewController ()

@end

@implementation firstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor colorWithRed:0.565 green:1.000 blue:0.994 alpha:1.000];

    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    self.name1.backgroundColor=[UIColor colorWithRed:0.905 green:0.903 blue:0.910 alpha:1.000];
    self.name1.delegate=self;
    [self.view addSubview:self.name1];

    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(150, 200, 100, 100)];
    [self.btn setTitle:@"下一页" forState:0];
    [self.btn addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
    self.btn.backgroundColor=[UIColor colorWithRed:0.210 green:0.257 blue:0.382 alpha:1.000];

    [self.view addSubview:self.btn];

}

//这个方法是执行多遍的  相当于刷新view

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
      //把contextStr赋值到first中文本框的内容中
    self.name1.text=[AppStatus shareInstance].contextStr;
}
-(void)next{

    sceondViewController *second=[[sceondViewController alloc]init];
    //把first中文本框的内容赋值到contextStr中
    [AppStatus shareInstance].contextStr=self.name1.text;
    NSLog(@"%@",[AppStatus shareInstance].contextStr);

    [self presentViewController:second animated:YES completion:nil];

}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.name1 resignFirstResponder];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

第二个页面sceondViewController.h

#import <UIKit/UIKit.h>
#import "AppStatus.h"
@interface sceondViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;
@end
#import "sceondViewController.h"

@interface sceondViewController ()

@end

@implementation sceondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor colorWithRed:1.000 green:0.416 blue:0.612 alpha:1.000];

    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    self.name1.backgroundColor=[UIColor colorWithRed:0.905 green:0.903 blue:0.910 alpha:1.000];
    self.name1.text=[AppStatus shareInstance].contextStr;
    self.name1.delegate=self;
    [self.view addSubview:self.name1];

    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(150, 200, 100, 100)];
    [self.btn setTitle:@"上一页" forState:0];
    [self.btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    self.btn.backgroundColor=[UIColor colorWithRed:0.210 green:0.257 blue:0.382 alpha:1.000];

    [self.view addSubview:self.btn];

}
-(void)back{

    //把second中的文本框的值赋值给单例类的contextStr
    [AppStatus shareInstance].contextStr=self.name1.text;
    NSLog(@"%@",[AppStatus shareInstance].contextStr);

    [self dismissViewControllerAnimated:YES completion:nil];

}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }
    return YES;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.name1 resignFirstResponder];
}

//这个方法是执行多遍的  相当于刷新view
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //把contextStr赋值到second中文本框的内容中
    self.name1.text=[AppStatus shareInstance].contextStr;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

把根视图转到第一个视图,最后代码和代理模式的一样,在AppDelegate的

4.通知传值(逆向传值)


注意:通知传值是逆向传值,只能在第二个页面创建通知和发送通知,在第一个页面接收通知,并读取通知里的信息

第一个页面

firstViewController.h

#import <UIKit/UIKit.h>
#import "secondViewController.h"
@interface firstViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;

@end

firstViewController.m

#import "firstViewController.h"

@interface firstViewController ()

@end

@implementation firstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor colorWithRed:0.565 green:1.000 blue:0.994 alpha:1.000];

    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    self.name1.backgroundColor=[UIColor colorWithRed:0.905 green:0.903 blue:0.910 alpha:1.000];
    self.name1.delegate=self;
    [self.view addSubview:self.name1];

    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(150, 200, 100, 100)];
    [self.btn setTitle:@"点击" forState:0];
    [self.btn addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
    self.btn.backgroundColor=[UIColor colorWithRed:0.210 green:0.257 blue:0.382 alpha:1.000];

    [self.view addSubview:self.btn];

    //添加通知

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(ChangeNameNotification:) name:@"order" object:nil];

}
//通知方法
-(void)ChangeNameNotification:(NSNotification *)notification{

    NSDictionary *nameDic=notification.userInfo;
    NSLog(@"%@",nameDic);
    self.name1.text=[nameDic objectForKey:@"key"];

}
-(void)next{

    secondViewController *second=[[secondViewController alloc]init];
    second.str=self.name1.text;
    [self presentViewController:second animated:YES completion:nil];

}
//移除通知
-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"order" object:nil];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    if ([textField  isFirstResponder]) {
        [textField resignFirstResponder];
    }
    return YES;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.name1 resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

第二个页面secondViewController.h

#import <UIKit/UIKit.h>

@interface secondViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;
@property(nonatomic,strong)NSString *str;
@end

第二个页面secondViewController.m

#import "secondViewController.h"

@interface secondViewController ()

@end

@implementation secondViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor=[UIColor colorWithRed:1.000 green:0.314 blue:0.659 alpha:1.000];

    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    self.name1.backgroundColor=[UIColor colorWithRed:0.905 green:0.903 blue:0.910 alpha:1.000];
    [self.view addSubview:self.name1];

    self.name1.text=self.str;

    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(150, 200, 100, 100)];
    [self.btn setTitle:@"上一页" forState:0];
    [self.btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    self.btn.backgroundColor=[UIColor colorWithRed:0.210 green:0.257 blue:0.382 alpha:1.000];

    [self.view addSubview:self.btn];

}
-(void)back{
    //创建通知
    NSNotification *no=[[NSNotification alloc]initWithName:@"order" object:self userInfo:@{@"key":self.name1.text}];
    //通知中心发送通知
    [[NSNotificationCenter defaultCenter] postNotification:no];
    [self dismissViewControllerAnimated:YES completion:nil];

}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }
    return YES;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.name1 resignFirstResponder];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*

把根视图转到第一个视图,最后代码和代理模式的一样,在AppDelegate的

5.代码块传值(逆向传值)



代码块传值步骤

/**

*  代码块传值 从后往前传值

1.声明代码块(secondXXX.h)

2.声明一个代码块的类型属性(secondXXX.h)

3.调用代码块(secondXXX.m)

4.实现代码块(FirstXXX.m)

第一个页面firstViewController.h和

#import <UIKit/UIKit.h>
#import "secondViewController.h"
@interface firstViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;

@end
#import "firstViewController.h"

@interface firstViewController ()

@end

@implementation firstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor redColor];
    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    self.name1.borderStyle=2;
    self.name1.delegate=self;
    [self.view addSubview:self.name1];

    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(200, 300, 100, 100)];
    [self.btn setTitle:@"下一页" forState:0];
    [self.btn addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:self.btn];
}

//-(void)postValue:(NSString *)str{
//
//    self.name1.text=str;
//}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }

    return YES;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.name1 resignFirstResponder];
}
-(void)next{
    secondViewController *second=[[secondViewController alloc]init];
    second.str=self.name1.text;

    second.myBlock=^(NSString *info){

        self.name1.text=info;

    };
//    second.deletage=self;
    [self presentViewController:second animated:YES completion:nil];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

第二个页面 firstViewController.h和firstViewController.m

#import <UIKit/UIKit.h>
typedef void(^postValueBlock)(NSString *info);
//@protocol postValueDeletage <NSObject>
//
//-(void)postValue:(NSString *)str;
//
//@end

/**
 *  代码块传值 从后往前传值
 1.声明代码块(secondXXX.h)
 2.声明一个代码块的类型属性(secondXXX.h)
 3.调用代码块(secondXXX.m)
 4.实现代码块(FirstXXX.m)

 */

@interface secondViewController : UIViewController<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *name1;
@property(nonatomic,strong)UIButton *btn;
@property(nonatomic,copy)NSString *str;
@property(nonatomic,strong)postValueBlock myBlock;
#import "secondViewController.h"

@interface secondViewController ()

@end

@implementation secondViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor=[UIColor grayColor];

    self.name1=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    self.name1.borderStyle=2;
    self.name1.text=self.str;
    //    self.name1.backgroundColor=[UIColor ];
    [self.view addSubview:self.name1];

    self.btn=[[UIButton alloc]initWithFrame:CGRectMake(200, 300, 100, 100)];
    [self.btn setTitle:@"上一页" forState:0];
    [self.btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:self.btn];

}

-(void)back{

//    if (self.deletage!=nil) {
//        [self.deletage postValue:self.name1.text];
//
//    }

    if (self.myBlock) {
        self.myBlock(self.name1.text);
    }

    [self dismissViewControllerAnimated:YES completion:nil];

}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.name1 resignFirstResponder];
}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

把根视图转到第一个视图,最后代码和代理模式的一样,在AppDelegate的

本文主要是使用第一个文本框的值传递到第二个页面的文本框中,修改第二个页面文本框中的内容,同时又显示到第一个页面的文本框中,为属性复制都写在几种传值的里面(除了单例传值)

时间: 2024-10-05 23:58:51

iOS 页面跳转传值,属性传值,代理传值,代码块传值,单例传值,通知传值的相关文章

iOS--页面间的代理传值(属性、代理(委托)、代码块、单例、通知)

(一)属性传值 第二个界面中的lable显示第一个界面textField中的文本 首先我们建立一个RootViewControllers和一个DetailViewControllers,在DetailViewControllers中声明一个textString属性,用于接收传过来的字符串, (三)代理传值 RootViewControllers页面push到DetailViewControllers页面,如果DetailViewControllers页面的信息想回传(回调)到RootViewCo

iOS 页面间几种传值方式(属性,代理,block,单例,通知)

iOS 页面间几种传值方式(属性,代理,block,单例,通知) 姜糖水 2015-05-03 52 阅读 iOS 移动开发 第二个视图控制器如何获取第一个视图控制器的部分信息 例如 :第二个界面中的lable显示第一个界面textField中的文本 这就需要用到属性传值.block传值 那么第一个视图控制器如何获的第二个视图控制器的部分信息 例如:第一个界面中的lable显示第二个界面textField中的文本 这就需要使用代理传值 页面间传值有八大传值方式,下面我们就简单介绍下页面间常用的五

iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)

iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例) 实现了以下iOS页面间传值:1.委托delegate方式:2.通知notification方式:3.block方式:4.UserDefault或者文件方式:5.单例模式方式:6.通过设置属性,实现页面间传值 在iOS开发中,我们经常会遇到页面间跳转传值的问题,现归纳总结一下: 情况1:A页面跳转到B页面 方法: 在B页面的控制器中,编写对应的属性,在A页面跳转到B页面的地方,给

iOS页面间传值的方式 (Delegate/NSNotification/Block/NSUserDefault/单例)

iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例) iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例) 实现了以下iOS页面间传值: 1.委托delegate方式:2.通知notification方式:3.block方式:4.UserDefault或者文件方式:5.单例模式方式:6.通过设置属性. 在iOS开发中,我们经常会遇到页面间跳转传值的问题,现归纳总结一

iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例)

实现了以下iOS页面间传值:1.委托delegate方式:2.通知notification方式:3.block方式:4.UserDefault或者文件方式:5.单例模式方式:6.通过设置属性,实现页面间传值 在iOS开发中,我们经常会遇到页面间跳转传值的问题,现归纳总结一下: 情况1:A页面跳转到B页面 方法: 在B页面的控制器中,编写对应的属性,在A页面跳转到B页面的地方,给B的属性赋值即可 //SecondViewController.h @property(nonatomic) NSInt

iOS页面跳转及数据传递

iOS页面跳转: 第一种 [self.navigationController pushViewController:subTableViewController  animated:YES]; //描述:通过 NSNavigationBar 进行跳转 [self.navigationController popViewControllerAnimated:YES]; //描述:在子视图返回到上级视图 第二种 UIViewController *control = [[UIViewControl

ios 页面跳转之间传递数据----通过delegate

主要参考了这篇博客http://mobile.51cto.com/iphone-284116.htm 主要用到了,两个类,一个delegate a类,调用b类,当b类执行之后,需要把一个数据传递给a类,a类把这个数据显示出来. 1.delegate,就这一个头文件就足够了.在类中去实现这个代理方法 #import <Foundation/Foundation.h> @protocolUIViewPassValueDelegate - (void)passValue:(NSString*)val

iOS 页面间几种传值方式(属性,代理,block,单例,通知)

第二个视图控制器如何获取第一个视图控制器的部分信息 例如 :第二个界面中的lable显示第一个界面textField中的文本 这就需要用到属性传值.block传值 那么第一个视图控制器如何获的第二个视图控制器的部分信息 例如:第一个界面中的lable显示第二个界面textField中的文本 这就需要使用代理传值 页面间传值有八大传值方式,下面我们就简单介绍下页面间常用的五种传值方式: (一)属性传值 第二个界面中的lable显示第一个界面textField中的文本 首先我们建立一个RootVie

iOS传值方式:属性,代理,block,单例,通知

第二个视图控制器如何获取第一个视图控制器的部分信息 例如 :第二个界面中的lable显示第一个界面textField中的文本 这需要用到属性传值.block传值 那么第一个视图控制器如何获的第二个视图控制器的部分信息 例如:第一个界面中的lable显示第二个界面textField中的文本 这就需要使用代理传值 页面间传值有八大传值方式,下面我们就简单介绍下页面间常用的五种传值方式: (一)属性传值 第二个界面中的lable显示第一个界面textField中的文本 首先我们建立一个RootView