I have a requirement where I have to pass a string value from one viewController to another on button click. I also need to switch from current viewController to secondViewController using tabBarController. I tried:
FirstViewController.h
#import "SecondViewController.h"
@property(nonatomic, strong) SecondViewController *secondController;
FirstViewController.m
-(IBAction)go:(id)sender
{
self.secondController.itemText=@"Demo Text";
self.tabBarController.selectedIndex=1; //say secondViewController index is 1
}
SecondViewController.h
#import "FirstViewController.h"
@property(nonatomic, strong) NSString *itemText;
SecondViewController.m
-(void) viewWillAppear (BOOL) animated
{
NSLog(@"Comes from FirstViewController: %@",self.itemText);
}
Though it switches the viewController but it prints blank. What's wrong with the code?