码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-04-18 01:09:01      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

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.

}

 

 

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

标签:

原文地址:http://www.cnblogs.com/varliny/p/4436395.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!