pushViewController animates the navigation bar but

2019-08-24 13:20发布

问题:

I've got an iOS app that is doing some crazy stuff... I'll do my best to describe it.

My navigation architecture is as follows:

AppDelegate calls this:

tabNavController = [[MainTabViewController alloc] initWithNibName:nil bundle:nil];
self.window.rootViewController = tabNavController;
[self.window makeKeyAndVisible];

MainTabViewController inherits from UITabBarController

Inside MainTabViewController's viewDidLoad, I programmatically load my tabs into an NSMutableArray and assign it to the tabControllers:

NSMutableArray *tabs;

StreamViewController *controller = [StreamViewController alloc] initWithNib...];
UINavigationController *navCon = [UINavigationController alloc] initWithRootViewController:controller];

[tabs addObject:navContorller];

...
self.viewControllers = tabs;

My very first tab -- the one that is displayed by default -- inherits from UIViewController. I have a UITableView setup in a XIB as the main view. My class is the UITableViewDelegate and UITableViewDataSource.

StreamViewController : BaseModuleViewController <UITableViewDelegate, UITableViewDataSource>

The table loads and displays fine. When a user clicks a row, I push a new view controller to the stack:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    
   ...
   DetailViewController* detailController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
   [self.navigationController pushViewController:detailController animated:YES];
   ...
}

This is where it gets strange. The view controller acts like its going to display, but it doesn't. I see my navigationBar animate -- my buttons shift around, the title changes, and a Back button shows up -- but the view itself does not display. I can even continue to click the table view cells and continually load more and more views, each new one animates the navbar and shows a new back button. I can then hit back X number of times to get "back" to my StreamViewController.

Here's the next kicker. If I navigate to tab #2, then back to tab #1, none of the above happens and the view appears exactly like it should.

Strange - anyone seen this and have an idea of what's going on?

EDIT

Here's a YouTube video showing it not working: http://youtu.be/Shces88d6Go

回答1:

Try to add a navigation controller as your root view controller.

tabNavController = [[MainTabViewController alloc] initWithNibName:nil bundle:nil];
    UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:tabNavController];
    self.window.rootViewController = navCtrl;
    [self.window makeKeyAndVisible];


回答2:

Found that I was launching a modal window in the viewDidLoad method of my MainTabViewController. This somehow confused the system and was the root of the problem.