ParentViewController returns nil - iphone

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

Related

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];

obtaining UINavigationController in an UIView

a custom tab bar controller I am using applies the ViewController or UINavigationController like this: UIViewController* viewController = [data objectForKey:#"viewController"];
I dont knw exactly how it works but "viewController" comes out as a UINavigationController. Next, the custom tab bar controller class adds a tag like so, viewController.view.tag = THE_TAG;
Retrieving the controller is uses UIView* currentView = [self.window viewWithTag:SELECTED_VIEW_CONTROLLER_TAG];
This part is where I get confused because now when I nslog this
"currentView" I get a UILayout etc... instead of my UINavigationController. I'm assuming it applied the tag to the UIView that contained the nav controller?
How do I reference the UINavigationController within this UIView?
In the above what is THE_TAG, and can you confirm that it is unique (i.e. not zero, and not matching something being used elsewhere by the same mechanism)?
I'd be pretty wary overusing tag since there is no easy way to gaurentee globally unique tags, and when using something like self.window viewWithTag you could see just about every view in the app being checked.
It seems like you have a view and a viewController confused. A UINavigationController is a subclass of UIViewController. It is not a subclass of UIView. UIViewControllers do have a property which is a UIView class. It is probably this property that you are accessing when you use viewWithTag: . So maybe, when you use that method, you are not accessing the UINavigationController but the UINavigationController's view property (which is actually something you should probably not be messing with.)

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.

UINavigationcontroller: Use a button to jump to other uiview from the tabbarcontroller

I havent tried this, yet. So is a kind of theoretical question.
I have a tabbarcontroller, and in one view, let us call it "stages", i want to have a button that give you a shortcut to the next tab bar item that is a mapview. In the mapview have I lot of annotations pins, that represent the position of several stages.
Resuming, I want a button in the stages view that jump directly to the annotation pin in the mapview in the next tabbar item.
Should I use like normally the [navigationcontroller pushcontroller: animated:] or exist other method to do it? In last case I will use normally push to another mapview.
If you want to directly jump to the other tab (you don't want a new viewcontroller in your navigationController, but want the other tab's VC), you can create a button or whatever that sets the selectedViewController property of your UITabBarController to the viewController in the other tab. (if your tabbarcontroller has constant tabs (they dont get changed)) you can do this by using the UITabBarController's viewControllers array. Something like this should work:
-(IBAction) jumpToMapTab:(id)sender {
myTabBarController.selectedViewController = [[myTabBarController viewControllers] objectAtIndex:indexOfMyMapTab];
}
`

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

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.