I have a rootcontroller pushed on a UINavigationController.
Inside that rootcontroller class, I can access the UINavigationController with this.NavigationController
However, this rootcontroller has a ScrollView and I’m adding subcontrollers (or more precise, the View of this subcontroller) to this ScrollView.
I would now like to access the UINavigationController from inside such subcontroller.
Following properties are all null
this.NavigationController
this.ParentViewController
this.PresentedViewController
this.PresentingViewController
It seems in ObjectiveC you can use following code
YourAppDelegate *del = (YourAppDelegate *)[UIApplication sharedApplication].delegate;
[del.navigationController pushViewController:nextViewController animated:YES];
Unfortunately, i don’t know how to map this to C# in MonoTouch.
I tried the following, but it’s not working:
UIApplication.SharedApplication.KeyWindow.RootViewController.NavigationController
I know I could pass the UINavigationController object to all my classes (parameter in constructor), but that’s probably not the cleanest way to go.
To extend poupou’s answer, here is an example of what I usually do in my
AppDelegateclass:Add a static property of the
AppDelegateitself:Add my root navigation controller as a property:
In
FinishedLaunching:This way, I can access the root view controller from anywhere, like this:
… instead of having to write this all the time:
Plus, I can directly access all other
AppDelegate‘s properties I might have.Hope this helps.