Jim Rota
Jim Rota

Reputation: 1781

How To Correctly Segue To An Embedded Tab Bar and Navigation Controller Using Storyboards?

I've got an app where the user selects their country from a picker wheel. An alert comes up and asks them to confirm the change. If they confirm, it takes them to a different view where they can then select from a list of categories to display information...

The list of categories is embedded in a Navigation Controller to facilitate moving from the detailed view "Back" to the category select view.

The entire app is embedded in a Tab Bar Controller.

It works fine (after selecting their country they are taken to the Select Category screen) except that now the Select Categories has lost its connection to the Tab Bar Controller and there is no way to get back to other parts of the app.

Here's my alertView code:

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

if (buttonIndex == 0) {
NSLog(@"ok");

//I tried the following but it doesn't do anything
//SelectCategory *switchtocategory = [[SelectCategory alloc] init];
//[self.navigationController pushViewController:switchtocategory animated:YES];

//the following works but loses the tab/navigation bars
[self performSegueWithIdentifier: @"GoToCategory" sender: self];

    } else {

    NSLog(@"cancel");

}

}

Upvotes: 1

Views: 1918

Answers (1)

Jim Rota
Jim Rota

Reputation: 1781

Finding the answer was really about understanding the role of the Tab Bar Controller, how it defaults as the root view controller and then how to work with it to access the various view controllers, instead of trying to segue. Reading the Apple documentation helped with this but the code turned out to be very easy:

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{

if (buttonIndex == 0) {

    NSLog(@"ok");

//the following transitions to tab #3 when the alertView is touched/clicked/dismissed

    [self.tabBarController setSelectedIndex:2];

    } else {

    NSLog(@"cancel");

}
}

Upvotes: 1

Related Questions