How to pushviewcontroller to a viewcontroller stored in a tabbaritem?

Posted by Jann on Stack Overflow See other posts from Stack Overflow or by Jann
Published on 2010-04-09T18:32:03Z Indexed on 2010/04/09 18:33 UTC
Read the original article Hit count: 626

First of all I know this is a long question. REST ASSURED I have tried to figure it out on my own (see: StackOverflow #2609318). This is driving me BATTY!

After trying and failing to implement my own EDIT feature in the standard moreNavigationController, I have decided to re-implement my own MORE feature.

I did the following:

Add a HOME view controller which I init with: initWithRootViewController

Add 3 other default tabs with:

ResortsListViewController *resortsListViewController;
resortsListViewController = [[ResortsListViewController alloc] initWithNibName:@"ResortsListView" bundle:nil];
resortsListViewController.title = [categoriesDictionary objectForKey:@"category_name"];
resortsListViewController.tabBarItem.image = [UIImage imageNamed:@"whatever.png"];
resortsListViewController.navigationItem.title=@"whatever title";
localNavigationController = [[UINavigationController alloc] initWithRootViewController:resortsListViewController];
localNavigationController.navigationBar.barStyle = UIBarStyleBlack;
[localControllersArray addObject:localNavigationController]; 
[localNavigationController release];
[resortsListViewController release];

Those work when i add them to the tabbar. (ie: click on them and it goes to the view controller)

Then I add my own MORE view controller to the tabbar:

MoreViewController *moreViewController;
moreViewController = [[MoreViewController alloc] initWithNibName:@"MoreView" bundle:nil];
moreViewController.title = @"More";
moreViewController.tabBarItem.image = [UIImage imageNamed:@"more.png"];
moreViewController.navigationItem.title=@"More Categories";
localNavigationController = [[UINavigationController alloc] initWithRootViewController:moreViewController];
localNavigationController.navigationBar.barStyle = UIBarStyleBlack;
[localControllersArray addObject:localNavigationController]; 
[localNavigationController release];
[moreViewController release];

Then

tabBarController.viewControllers = localControllersArray;
tabBarController.moreNavigationController.navigationBar.barStyle = UIBarStyleBlack;  
tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil];
tabBarController.delegate = self;

That creates the necessary linkages. Okay, so far all is well. I get a HOME tab, 3 category tabs and a customized MORE tab -- which all work.

in the MORE tab view controller I implement a simple table view that displays all the other tabs I have in rows. SINCE I want to be able to switch them in and out of the tabbar I created them JUST like i did the resortslistviewcontroller above (ie: as view controllers in an array). When I pull them out to display the title in the tableview (so the user can go to that "view") i simply do the following:

    // [myGizmoClass CategoryArray] holds the array of view controller tab bar items that are NOT shown on the main screen.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ... etc...

        UIViewController *Uivc = [[myGizmoClass plusCategoryArray] objectAtIndex:indexPath.row];
        cell.textLabel.text = [Uivc title];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

THIS is where it falls through:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    MyGizmoClass *myGizmoClass= [MyGizmoClass sharedManager];

    UIViewController *tbi = [[myGizmoClass plusCategoryArray] objectAtIndex:indexPath.row];
    NSLog(@"%@\n",[[tbi navigationItem ]title]);

    [self.navigationController pushViewController:tbi animated:YES];

}

This is the error i get ("ATMs" is the title for the clicked tableview cell so i know the Uivc title is pulling the correct title and therefore the correct "objectatindex":

2010-04-09 11:25:48.222 MouseAddict[47485:207] ATMs 2010-04-09 11:25:48.222 MouseAddict[47485:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

BIG QUESTION: How do i make the associated VIEW of the UIViewController *tbi show and get pushed into view?

I am GUESSING that the UIViewController is the correct class for this tbl .. i am not sure. BUT i just wanna get the view so i can push it onto the stack.

Can someone plz help?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uiviewcontroller