-2

I want to pass value and display from ViewController1 to ViewController2, when I go to ViewController2. The data did not display on the view. But I check po data.odrNum it has the value in it.

ViewController1

ViewController2 *data = [[ViewController2 alloc] init];
data.odrNum = [respondData valueForKey:@"orderCode"];

ViewController2.h

@property (strong, nonatomic) NSString *odrNum;

ViewController2.m

self.orderConNum.text = self.odrNum;

And this is the way I present my ViewController2

 UIStoryboard * storyboard = self.storyboard;
    OrderDetailsViewController *detail = [storyboard instantiateViewControllerWithIdentifier: @ "OrderDetailsViewController"];
    [self.navigationController pushViewController:detail animated:YES];

2 Answers2

-1

Pass data when you push viewcontroller .

UIStoryboard * storyboard = self.storyboard;
OrderDetailsViewController *detail = [storyboard instantiateViewControllerWithIdentifier: @ "OrderDetailsViewController"];

detail.odrNum = [respondData valueForKey:@"orderCode"];  // this line you must put when you want to pass data. 

[self.navigationController pushViewController:detail animated:YES];
Himanshu Moradiya
  • 4,769
  • 4
  • 25
  • 49
-1

Have you considered using a sharedSingleton:

In the dropbox file is the sharedSingleton files I use.

In the Changables.h file you can add the variables you want to use and you can import it on the UIViewControllers you want to use.

To set this you only have to use:

[Changables sharedSingleton].yourVariable = @"my variable data"

and to get the data back you can just use

[Changables sharedSingleton].yourVariable.

I have used this to use custom Objects as well.

Himanshu Moradiya
  • 4,769
  • 4
  • 25
  • 49
Burnie777
  • 395
  • 5
  • 18