2

How is it possible to map the initWithRootViewController objective-c method in Monotouch?

From Miguel de Icaza Rosetta site, I've found the following translation but I don't know how to apply it:

Selector: initWithRootViewController:
Method: IntPtr Constructor (UIViewController rootViewController);

Then, I also have another problem to solve. I would change the UINavigationController RootViewController during runtime. Is it possible? Surfing the Web, I've found this Changing a UINavigationController’s Root View Controller. Is there a more simple solution?

Thank you in advance.

Edit: my goal is to map the initWithRootViewController method (provided in the link) in Monotouch.

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190

1 Answers1

2

To answer your first question - you simply create a new UINavigationController as below:

UINavigationController navController = new UINavigationController(rootViewController);

Technically it would be possible to change the root controller by modifying the ViewControllers property. For example:

navController.ViewControllers = new UIViewController[2] { newRootController, childController }

EDIT

Try adding the following constructor to your custom UINavigationController:

public CustomNavController(UIViewController rootViewController)
{
    ViewControllers = new UIViewController[1] { rootViewController };
}

I'm not sure if this is the best way to get it done, but it'll work.

Luke
  • 3,665
  • 1
  • 19
  • 39
  • Hi Luke, thank you. The first answer doesn't work for me. I haven't a ctr that takes an UIViewController. Could you help me on adopt the solution I provided in the above link. I would create a custom navigationcontroller but I can't understand how to use rosetta. Thank you again. – Lorenzo B Mar 29 '11 at 13:22
  • What is your app's hierarchy like? You've got a little confused as to why this won't work for you.. – Luke Mar 29 '11 at 13:25
  • beacause I haven't a ctr like the one you provided. Check the edit. – Lorenzo B Mar 29 '11 at 13:27
  • 1
    Could try adding the constructor I've added in the edit. That'll provide the easiest solution of initially setting the rootViewController. About to head into a meeting so don't have time to help with the second problem right now but if I get a moment later, I'll see what I can do – Luke Mar 29 '11 at 13:34
  • Thank you very much. I've added the ctr. Do I have to call it with any base method?`public CustomNavController(UIViewController rootViewController) : base ...` thank you! – Lorenzo B Mar 29 '11 at 14:01