Reputation: 131
I have one page(say X) before tab bar controller that use model segue to open tab bar controller. Also first screen of tab bar controller is same with X.
I want to pass data from X to tab bar controller's first page.
Shortly, I want to pass data from view controller to tab bar controller page with storyboard segue. Is there any method for this ?
Here is the solution ;
locationsHome* vc = [[locationsHome alloc] init];
UITabBarController* tbc = [segue destinationViewController];
vc = (locationsHome *)[[tbc customizableViewControllers] objectAtIndex:0];
Upvotes: 4
Views: 8691
Reputation: 35783
For Swift 2.2, I had to modify accepted answer this way
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if (segue.identifier == "userAccountSegue")
{
var firstTabViewController: UserAccountViewController = UserAccountViewController()
let tabViewController: UITabBarController = segue.destinationViewController as! UITabBarController
firstTabViewController = (tabViewController.customizableViewControllers![0] as! UserAccountViewController)
firstTabViewController.userObj = arrayForTable![selectedIndex] as? User
}
}
Note : Hint for above code snip
Upvotes: 0
Reputation: 2658
//if sent to First Tab of Tab Bar Controller
UITabBarController *tabBarController = segue.destinationViewController;
UINavigationController *navigationController = (UINavigationController *)[[tabBarController viewControllers] objectAtIndex:0];
createTeamViewController *controller = (createTeamViewController *)[[navigationController viewControllers] objectAtIndex:0];
controller.userProfile = self.userProfile;
Upvotes: 2
Reputation: 131
This is how I solved my problem. You can pass data from ViewController to TabBarController with this method.
Use this code within prepareForSegue
method
locationsHome* vc = [[locationsHome alloc] init];
UITabBarController* tbc = [segue destinationViewController];
vc = (locationsHome *)[[tbc customizableViewControllers] objectAtIndex:0];
Like this:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSString * segueIdentifier = [segue identifier];
if([segueIdentifier isEqualToString:@"tabbarGo"]){
locationsHome* vc = [[locationsHome alloc] init];
UITabBarController* tbc = [segue destinationViewController];
vc = (locationsHome *)[[tbc customizableViewControllers] objectAtIndex:0];
etc...
}
}
Upvotes: 9
Reputation: 438467
Add a property to the destination view controller (the subclassed tab bar controller) and then in the source view controller, implement prepareForSegue
to pass information to the destination controller. You can then have the destination view controller's viewDidLoad
to act upon the data that was passed to it in the prepareForSegue
of the source view controller.
Upvotes: 0