Suppose I have two view controllers, ViewControllerA and ViewControllerB , when I click a button from ViewControllerA , it clicks on ViewControllerB . However, before clicking, I want to set the ViewControllerB property from ViewControllerA . But all I get is nil when I check the variable from ViewControllerB . What am I doing,
In ViewControllerA :
VCB = [[ViewControllerB alloc]init]; [VCB setPropertyOfViewControllerB:someString]; NSLog(@"value: %@", VCB.PropertyOfViewControllerB);
but the fact is, I also want to achieve this from ViewControllerB , but I get nil for the variable.
In ViewControllerB :
//I already defined in h file as property NSString *PropertyOfViewControllerB; @property(nonatomic, retain) NSString *PropertyOfViewControllerB;
But when I try to check the value in the viewDidLoad method ViewControllerB
NSLog(@"value: %@", PropertyOfViewControllerB);
Perhaps I missed a small point that I could not understand. Any help would be awesome. Thanks.
Edit: I am using storyboards. I click the following code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; lvc = [storyboard instantiateViewControllerWithIdentifier:@"mainManu"]; [self.navigationController pushViewController:lvc animated:YES];
source share