0
votes

I have a TabBar application with several nibs, most with a NavBar. It works pretty well, except for the "views" that are inside the "More" section of the tabBar.

As expected, it will put a NavBar to return to the "More" list, as well as the NavBar i've placed in the nib.

I've tried to remove the view controllers from the moreNavigationBar and put the top controller from my nib's navBar, but I get and extra view from somewhere:

- (void)viewDidLoad {    
    TestAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    UITabBarController *ctrl = appDelegate.rootController;

    UINavigationController *navCtrl = ctrl.moreNavigationController;

    [navCtrl popToRootViewControllerAnimated: NO];
    [navCtrl pushViewController: navController.topViewController animated: YES];
    navController = navCtrl;
 [super viewDidLoad];
}

My AppDelegate:

@interface TestAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
 UITabBarController *rootController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *rootController;

The MainWindow nib is that of a Window-based project with a TabBarController, linked to the rootController in my app delegate.

The other nibs have a view + navigationController and I have a UITableViewController subclass as my Root View Controller.

If I could get this to work it wouldn't still solve my problem, because I want to allow the user to place this anywhere in the tabBar, so, I must have some way of knowing if there's a navigationBar.

So, my question is, how do you know if there's a navigationBar (in this case, if the tabBar's navigationBar is being shown) and, if so, how do I get my navigationController to "become" the tabBar's navigationController?

Or, if you have another idea on how to solve this problem, i'd also be appreciated :)

1

1 Answers

1
votes

The recommendation from apple is that you have the TabBar controller contain the Navigation controllers and not the other way around. I have a setup more or less like this, and I have the More tab hold a Nav controller, basically like this:

@interface SomethingNavViewController : UIViewController {
    UIView* aview;
    UINavigationController *navigationController;
}
@property (nonatomic, retain) IBOutlet UIView *aview;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

@end

In the NIB, I have a separate Nav controller in the view of the more panel, I haven't replaced the tab bar item's view with a nav controller view, I've just added a Nav controller to the view.

In my implementation file, I have:

- (void)viewDidLoad {
    [super viewDidLoad];
    [[self view] addSubview:[navigationController view]];
    SomeOtherController *aController = [[[SomeOtherController alloc ] initWithNibName:@"SomeOtherController" bundle:nil ] autorelease];
    aController.title = @"Artwalks";
        // lots of application logic here.
    [self.navigationController pushViewController:aController animated:YES];
    [self.navigationController setDelegate:self];
}

One key thing about this is that I have implemented the navigationController's delegate method, which is really handy when you're just inserting the nav controller. I found when I didn't do this, my views don't get viewDidAppear messages, so I implemented the protocol and added this method:

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if ([viewController respondsToSelector:@selector(viewDidAppear:)]) {
        [viewController viewDidAppear:animated];
    }
}

and that solved a variety of my lingering problems.

Anyway, I hope this answer gave you the detail you needed. IF it didn't, please give more details about your question. I'm not quite sure what but I get and extra view from somewhere met, but it sounds like something I encountered before I found this solution.