首页 > 代码库 > 页面之间传值,常见的几种方式。

页面之间传值,常见的几种方式。

ViewController页面传到TwoViewController页面name的值:两个页面都拥有一个字符串对象,跳转之前,把对象传过去。

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (nonatomic,copy)NSString *name;

@end

- (void)viewDidLoad {

    [super viewDidLoad];

       self.name = @"ranki";

    TwoViewController *two = [[TwoViewController alloc]init];

    two.name = self.name;

//    [self.navigationController pushViewController:two animated:YES];

    [self presentModalViewController:two animated:YES];

}

 

@interface TwoViewController : UIViewController

@property (nonatomic,copy)NSString *name;

 

@end

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~%@",self.name);

}

页面之间传值,常见的几种方式。