Three20 navigation by openURLAction; self.navigationController is nil in pushed VC? - iphone

The navigation commences with [[TTNavigator navigator] openURLAction:theUrl]; from one UIviewController controller and another UIViewController is the target of that URL. The map is set with set with the following code and there is no doubt navigation goes to the right place:
TTURLMap* map = navigator.URLMap;
[map from:#"tt://goToMyViewController" toViewController:[MyViewControllerClass class]];
In the pushed view controller i want to manipulate the image on the Back button but don't want to change the title. It should always be the title of the view controller this one was pushed on top of, or localized "Back" if no title was set.
Problem:
In this pushed view controller's viewDidLoad I'm starting with
NSArray* viewControllers = self.navigationController.viewControllers;
to get the navigation stack so I can look at the title of the appropriate view controller. But viewControllers is nil...
However if I do nothing the default back button does have the correct title. I thought of looking at the leftBarButtonItem and backBarButtonItem title properties but there is nothing meaningful there either...
Anyone know what is going on, why this is happening or how it can be worked around?

This is one of those things where viewDidLoad is the wrong place to do it - after comparing various view controllers and finding no real difference in how they were invoked (yet had nil viewControllers while others didn't) it struck me that if it was really nil, popViewControllerAnimated shouldn't work either. I found viewControllers was NOT nil where I was calling popViewControllerAnimated and from there experiment showed I could get the title I was after in viewWillAppear:.
So, viewWillAppear: seems to be a reliable place to touch self.navigationController while viewDidLoad is not.

Related

UITabBarController's first view of type UINavigationController not acting quite right

So I've got a UITabBarController as a view in my app, the first tab of which is a UINavigationController. I have a button inside this view that pushes another, custom view onto the stack:
myViewController *vc = [[myViewController alloc] init];
[self pushViewController:myOtherView animated:YES];
The class myViewController has things that are supposed to happen inside of both -viewDidLoad and -viewDidAppear:(BOOL)animated, but if I hit my button right after the UITabBarController view appears, neither of those methods seem to be called. And even stranger, when I hit "Back", the view does not animate away, but rather the view underneath it in the stack just pops back into place.
However, if I go to another tab in the tab bar, then go back to the first tab, then hit my button again, my custom view controller animates in, -viewDidAppear:(BOOL)animated is called, and it animates out of view upon hitting "Back" like it should. Unfortunately, -viewDidLoad is never called.
I'm really trying to get away from using Interface Builder for everything; I want to create this view controller purely programatically, but these weird issues aren't helping. Can anyone think of a reason for this bizarre behavior?
Edit: Even if I create my view controller via IB, this behavior still occurs. What's the deal? Do I need to do something to the UITabBarController?
Edit #2: Here's how I want my views to bet set up:
UITabBarControler
Tab 1: UINavigationController
UIViewController to be pushed onto the stack
UIViewController to be pushed onto the stack
etc (possibly more UIViewControllers)
Tab 2: UIViewController
Tab 3: UINavigation Controller
UIViewController to be pushed onto the stack
UIViewController to be pushed onto the stack
You don't say what kind of object contains the code you posted but, if it's handling a button action, it's probably a custom view controller that's managed by your navigation controller. If that's true, then you'd want [self.navigationController pushViewController:myOtherView animated:YES];.
(If self is some other kind of object or self.navigationController is nil, then you would need to add some more details about your current view controller structure.)

popToRootViewControllerAnimated doesn't modify attached navigationItem

My UIViewController calls a function on my rootViewController which then called popToRootViewControllerAnimated to return the view to the rootController. This all works - great!
Unfortunately the UINavigationItem (toolbar at the top) seems to display a mashup of both the rootViewController and the UIViewController that has just been removed.
What do I need to do? What have I done wrong?
The navigation bar doesn't remember changes that were made to it, so when you push a new controller, the navigation bar is altered to give the title of the new view controller, but it doesn't store what was there for the previous view controller.
You will need to recreate the items in the toolbar each time you come back to the view controller that has custom items.
You might be able to do this on viewWillAppear instead of viewDidLoad. I can't recall exactly, but you should recreate custom controls on navigation toolbar because it does not get preserved when a new view controller is pushed.
It seems that calling popToRootViewController from the rootViewController messes things up. TO rectify this I called the following from within the calling UIViewController
[self.navigationController popViewControllerAnimated:YES];

UINavigationController TitleView not displayed from ViewController NavigationItem

Whenever I add a viewController to a navigationController while in landscape the title view appears on certain views but not on others. ie: I have a navigation controller, add 3 view controllers, first two show titleview appropriately, third one doesn't show one at all. But the navigation controller grabs the titleview from the ViewController like it's supposed to, I wrote the value of it to the console and it is correct, but it just doesn't show on the screen for whatever reason. Any ideas?
Oh yeah works perfectly while in portrait orientation.
Here's another fun part, if I push the trouble view controller into the navigationController in landscape the titleView isn't there, then without any user interaction, I rotate the device back to portrait and the titleView appears, then I rotate the device back to landscape and it stays!
It's like the drawing of my TitleView was blocked even though I used InvokeOnMainThread. Nothing is running in the main thread (or anywhere for that matter) during that call.
Here's my structure:
Window
TabBarController
NavigationController
ViewController
NavigationController
ViewController
Here's my order of operations:
Create View Controller
Add Title view to view controller
Push View Controller onto NavigationController (InvokeOnMainThread)
Have you tried setting the controller title after the controller is pushed? This kind of behavior happens to me and the way to make sure the title appears is to mandatory set the navBar title in the viewDidLoad or viewWillAppear method as follows:
self.navigationController.navigationBar.topItem.title = #"The title";
or
self.navigationItem.title = #"The Title";
Other thing that happened to me is to set the leftBarButton or RightBarButton of a navigation bar without success in the viewDidLoad method, but they appear correctly when setting the bar buttons in the viewWillAppear method.
Hope this helps.
I think your problem maybe that when your function is called, the navigation item is nil. So when you call self.navigationITem.title, it do nothing. Later, when the view is rotated, the navigationItem is not nil anymore so changing the title works.
If you do the code in ViewDidLoad function beware that ViewDidLoad is called the first time someone calls viewController.view and not the first time the view is displayed. So the view may not be in a navigationController yet.
For example, this can happend if you do :
viewController.view.backgroundColor = ... ;
[navigationController pushViewController:viewController]
The first line will call ViewDidLoad even if the controller is not in a navigationController yet.

Getting empty view and blank navigation bar when I use popViewControllerAnimated

I'm writing an iPhone app that is based on a UINavigationController. I'm pulling data from a server that sometime returns bogus links. I open each link by pushing a webview viewcontroller. I want to be able to include some error handling. I know if the link is no good. So I want to be able to pop the webview view controller as soon as I know that my webview has encountered an error.
Currently, I've tried using the following code:
[self.navigationController popViewControllerAnimated:YES];
I then get a Navigation bar with nothing displayed in it, but if I click where the "back" button should be it operates appropriately. The title pops up when I click where the "back" button should be. The view where the viewcontrollers usually display there content is blank white too even though I'm popping back to a UITableViewController.
I've tried this as a workaround:
UINavigationController *nav = self.navigationController;
[self.navigationController popViewControllerAnimated:YES];
[nav.visibleViewController.view setNeedsDisplay];
I've checked the viewControllers array in the UINavigationController and it has the right viewcontrollers in it (ie it has removed the viewcontroller for the webview).
I also tried putting code in the viewWillAppear of the viewcontroller I'm popping back to, but the method is never getting called.
I'm looking for a way to force the UINavigationController to reload the same way that you can call reloadData on a UITableView.
Any help would be greatly appreciated.
I saw something like this on my app where I was using a navigation bar I added in Interface Builder on the root view of a navigation controller and then programmatically creating the nav bar and its subviews for the second view. When I would pop the second view to return to the first view I would hide the self.navigationcontroller bar which would show the white space underneath until the IB nav bar of the previous view appeared. To fix this I decided to stick with programmatically creating all my navbars which fixed the issue for me.
TL;DR - if you are using both IB and programmatically made navbars this can happen when popping views, stick with one or the other for all the navbars yo

ParentViewController returns nil

I know there are many questions on this, but I don't get it to work.
I present a UITabBarController with the presentModalViewController. However when I try to get title from the navigationItem title attribute in the UINavigationController class that presents the tabcontroller, it returns nil no matter what I do. I have the NSLog in the viewDidLoad method in tabcontroller class.
I also cast the UIViewController which is returned by the self.parentViewController property.
Then I try to access the title through: NSLog(#"%#", castedViewController.navigationItem.title);
Any suggestions?
you talking about two different thing. The first is a UITabBarController, the thing you have at the bottom two or more buttons. The second thing is a UINavigationController which is on the top of each view presenting a title and a back button.
If you present the tabBar modally then you would not get a back button, you should push it instead. (something like navigationController-pushView can't name it exactly for now).
Anyway try not to call the navigationItem.title but instead navigationBar.topItem.title