Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - passing data to pushed viewcontroller

When pushing a viewcontroller, how do I pass data long with it as well (such as "asdf":123)? Are you supposed to addObjects to a NSBundle?

like image 449
KaiserJohaan Avatar asked Nov 02 '11 12:11

KaiserJohaan


2 Answers

MyViewController * myVC = [[MyViewController alloc] initWithNibName:nil bundle:nil];
myVC.someProperty = someValue;    // Pass your data here
[self.navigationController pushViewController:myVC animated:YES];

And in your MyViewController class :

.h

@interface MyViewController : UIViewController
@property (nonatomic, strong) NSString * someProperty;
@end

.m

@implementation MyViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
        // your data has been set
        // self.someProperty is equal to "some value"
    }
like image 53
Zoleas Avatar answered Dec 10 '22 08:12

Zoleas


I don't believe you can, but of course you can add relevant properties or methods to your ViewController class and use these prior to pushing it.

like image 41
Clafou Avatar answered Dec 10 '22 09:12

Clafou