IOS各种传值之一(对象传值)

1:在不同的controllerview之间通过对象进行传值

  //传值方向 从A到B

  //A控制器

 

界面:

技术分享

//

//  ViewController.h

//  Index

//

 

 

#import <UIKit/UIKit.h>

#import "Person.h"

 

@interface ViewController : UIViewController

 

@property (weak, nonatomic) IBOutlet UITextField *name;

@property (weak, nonatomic) IBOutlet UITextField *sex;

@property (weak, nonatomic) IBOutlet UITextField *age;

 

@end

 

 

//

//  ViewController.m

//  Index

//

 

#import "ViewController.h"

#import "BController.h"

 

@interface ViewController ()

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

- (IBAction)pushBB:(id)sender {

    BController *bc=[[BController alloc]initWithNibName:@"Bcontroller" bundle:[NSBundle mainBundle]];

 

    Person *person=[[Person alloc]init];

    person.name=self.name.text;

    bc.bsex.text=self.sex.text;

    

    bc.person=person;

    

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

}

 

 

//B控制器

#import "ViewController.h"

#import "Person.h"

 

@interface BController : ViewController

@property (weak, nonatomic) IBOutlet UILabel *bname;

@property (weak, nonatomic) IBOutlet UILabel *bsex;

@property (weak, nonatomic) IBOutlet UILabel *bage;

@property (nonatomic,retain)Person *person;

 

 

 

@end

 

 

 

 

#import "BController.h"

 

@interface BController ()

 

@end

 

@implementation BController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    self.bname.text=self.person.name;

    NSLog(@"%@",self.bsex.text);

    

    // Do any additional setup after loading the view.

}

 

- (IBAction)popBB:(id)sender {

    [self dismissViewControllerAnimated:YES completion:nil];

}

 

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。