views:

44

answers:

1

Hi,

I have a UITabbarController set by the Interfacebuilder. The tabbarcontroller has 5 tabs, the first is a welcome page, and the second is a UITableViewController. Both have a NavigationController. The 2nd tab should show a category list. When I launch the app, all is fine. When I press the 2nd tab, it load the view perfectly with the navigation controller. But what I want to do is to be able to load a certain category in the 2nd tab using a link in the first tab.

So what I did was I added the following function in my appDelegate and call is from the view in my first tab:

- (void)loadCategoryViewUsingCategoryId:(NSString*)categoryId
{
    CategoryViewController *categoryView = [[CategoryViewController alloc] initWithLoadingCategoryUsingCategoryId:categoryId];

    if (!categoryView) {
        UIAlertView *errorView;
        errorView = [[UIAlertView alloc]
                     initWithTitle: NSLocalizedString(@"Whoops", @"oddsAppAppDelegate")
                     message: NSLocalizedString(@"I did not found the requested category. Sorry!", @"oddsAppAppDelegate")
                     delegate: self
                     cancelButtonTitle: NSLocalizedString(@"Close", @"oddsAppAppDelegate") otherButtonTitles: nil];
        [errorView show];
        [errorView autorelease];
    }
    else {
        self.tabBarController.selectedIndex = 1;

        self.tabBarController.selectedViewController = categoryView;
        [self.tabBarController.selectedViewController setTitle:@"apa"];
        [self.tabBarController.selectedViewController viewDidLoad];
    }
}

This works perfectly, BUT... when the 2nd tab is loaded it doesn't have the navigation controller toolbar. How can I load it so I keep my navigation controller toolbar?

The "CategoryViewController" is a UITableViewController by the way.

Best regards,
Paul Peelen

+1  A: 

The Navigation Bar shall be visible by default. If you want to access it directly with

[[self navigationController] setNavigationBarHidden:NO];

I think your problem is somewhere else. If you assign your controllers like this

UITabBarController *theTabBar = [[UITabBarController alloc]init];
YourWelcomeViewClassHere *welcome = [[YourWelcomeViewClassHere alloc] initWithNibName:@"YourWelcomeViewClassHere" bundle:nil]; //Or other custom initalizers
UINavigationController *welcomeNav = [[UINavigationController alloc] initWithRootViewController:welcome];
CategoryViewController *category = [[CategoryViewController alloc] initWithNibName:@"CategoryViewController" bundle:nil]; //Or other custom initalizers
UINavigationController *categoryNav = [[UINavigationController alloc] initWithRootViewController:category];
/*
Your other View controllers initializations
*/

NSArray *viewControllers = [[NSArray alloc] initWithObjects:welcomeNav,categoryNav,/* other viewControllers ,*/nil];
[theTabBar setViewControllers:viewControllers];

This might work and show your views.

Erle
Hi,I tried that, but it doesn't really work for me. Then again, your post started me thinking and gave me the following solution: self.tabBarController.selectedIndex = 1; UINavigationController *nav = [self.tabBarController.viewControllers objectAtIndex:1]; nav.viewControllers = [[NSArray alloc] initWithObjects:categoryView, nil];This worked for me. Regards,Paul Peelen
Paul Peelen