Reputation: 1548
I have UIViewController
and UITabBarController
.
UIViewController
contain 5 buttons and UITabBarController
has 5 Tabs.
By tapping first button app shows TabBarController
with the first selected tab, second - TabBarController
with the second tab and so on...
To prepare this I have used Modal-segue
for every button.
Everything works well.
Now I need to create "Home" button (may be programmatically) on TabBarController
's UINavigationBar
, which will execute "Go home view" action.
Edited with more details
{see the screenshot below}
There are TWO modal-segues between 1 and 2 (two buttons - two segues)
In my prepareForSegue in UIViewController:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
AppDelegate *d = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if ([segue.identifier isEqualToString:@"s1"]) {
d.initialTab = 0;
}
else if ([segue.identifier isEqualToString:@"s2"]) {
d.initialTab = 1;
}
}
In my viewDidLoad in UITabBarController:
TabController *mainTabController = (TabController *)self;
AppDelegate *d = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[mainTabController setSelectedIndex:d.initialTab];
This is works!
But I need to go back to home-page. So if there is a NavigationController after TabBarController I would like to create a button in NavigationBar.
Upvotes: 0
Views: 1761
Reputation: 2745
I suggest you to take a one Navigation Controller as a parent.
Then, add your Startup View as a root view of it.
On your main view controller page,
- (void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBarHidden = NO;
}
So, it will hide your main navigation. So no need to worry for this internal navigation flow.
And for internal navigation, you have already taken different navigation controllers.
By using code:
[self.parentViewController.navigationController popToRootViewControllerAnimated:YES];
you'll be at root of the application and it will poped out all view controller which were stacked in application.
Hopefully, you'll understand flow & will apply if you feel good.
Enjoy Coding.
Thanks.
Upvotes: 1