views:

134

answers:

2

I'm accessing a navigation controller from the app delegate and trying to push another view:

[appDelegate.myNavigationController pushViewController:self.detailView animated:YES];

but nothing is happening. The above is in myTableView.

The app is tabbar based. I added a NavigationController object under the TabbarController object in IB. Then I created a reference to myNavigationController in the app delegate.

Any suggestions how I can figure out why the above code isn't working? It works if addSubview to the current view.

+1  A: 

Make sure that appDelegate is not null (wherever you're getting it from is returning the right value), appDelegate.myNavigationController is not null (the IBOutlet was setup properly), and that appDelegate.myNavigationController.window is not null (it is currently displayed on the top of the stack.

Also make sure that any animations of previous pushing or popping of views are complete before you push your new item.

Ed Marty
Thanks. IBOutlet wasn't connected.
4thSpace
In the detailView, I'm doing this in viewWillAppear: appDelegate.myNavigationController.navigationItem.rightBarButtonItem = self.myButton but no button appears. I see the instances are valid. Any ideas what I'm doing wrong?
4thSpace
You should probably ask another question for that. However, off the top of my head, the navigationItem applies to the view controller shown within the navigation controller, not the navigation controller itself. You want appDelegate.myNavigationController.topViewController.navigationItem.rightBarButtonItem. Or more succinctly, you probably just want self.navigationItem.rightBarButtonItem.
Ed Marty
A: 

This may not be an answer to your question.

Your code looks confusing. Is the snippet from a UITableView subclass or from a UITableViewController subclass? What makes me ask is that your argument for pushViewController: is self.detailView. Keeping the distinction clear is extremely important.

If the code is being called from a view controller that shows a navigation bar, then you should be using self.navigationController rather than adding a property to appDelegate.

In particular, you need to be using the navigation controller in your tab.

Any of these could cause a problem with the view not appearing.

Paul Lynch
myTableView is a UIViewController. How will the detailView access the navigation controller if it is on myTableview? detailView would need a reference to myTableView (the parent) right? I'd rather avoid that because it becomes a circular reference.
4thSpace
If detailView is a UIViewController that you have pushed (and it has to be, for your code snippet to work), then it has a navigationController property that is set when you push it.
Paul Lynch