0

I would like to transfer some data, for example an integer, from ViewController1 to ViewController2. How would I do that? In other words, how would I be able to access the information from ViewController1 in ViewController2? Please specify all the required code. Thanks!!

  • 1
    Can you tell us [what you've tried](http://whathaveyoutried.com)? – Tim Sep 25 '12 at 16:08
  • "Please specify all the required code" ??? I learnt it myself, from book, go read a book about iPhone development and it will explain all about this sort of stuff, – Fogmeister Sep 25 '12 at 16:13

1 Answers1

0

When you push to the second view controller you will use some code like this...

MyViewController *vc2 = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];

[self.navigationController pushViewController:vc2];

in order to pass information to it you need to set up a property in MyViewController.h file like this...

@property NSString *someNameProperty;

Then when you push do this...

MyViewController *vc2 = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];

vc2.someNameProperty = @"This is being passed to view controller 2";

[self.navigationController pushViewController:vc2];

Then in vc2 you can access the same property self.someNameProperty and it will contain the value you passed in from vc1.

Hope this helps.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306