4

It's easy to create a multi-level menu structure using nested RootElements in MonoTouch.Dialog but how would you go about having a specific UIViewController manage each root instead? The reason I want each RootElement to have it's own UIViewController is because I want to be able to easily control things like background image and toggling the NavigationBar from screen to screen and doing so is trival from within a UIViewController.

poupou
  • 43,413
  • 6
  • 77
  • 174
Brian David Berman
  • 7,514
  • 26
  • 77
  • 144

2 Answers2

9

I think you're looking for this:

public RootElement (string caption, Func<RootElement, UIViewController> createOnSelected)

which let you create the UIViewController (e.g. a DialogViewController that you customized or a type that inherit from it).

This will let you keep nesting your Element while giving most of the control over the view and it's controller.

UPDATE

Here's how this can be used:

First declare your method that will create the UIViewController. The method signature must match Func<RootElement, UIViewController>, e.g.

    static UIViewController CreateFromRoot (RootElement element)
    {
        return new DialogViewController (element);
    }

Next create your root elements using:

    var root_element = new RootElement ("caption", CreateFromRoot);

The above will give you the same as:

    var root_element = new RootElement ("caption");

except you're now able to customize the DialogViewController to your liking before returning it.

Chuck Savage
  • 11,775
  • 6
  • 49
  • 69
poupou
  • 43,413
  • 6
  • 77
  • 174
  • What does the code for createOnSelected look like? Also, you have "public" in there, do you mean "new"? – Brian David Berman Dec 18 '11 at 22:01
  • 1
    No, what's above is the constructor declaration (from MonoTouch.Dialog) that you should use in your code (by doing a new). I'll update answer to show this. – poupou Dec 18 '11 at 23:32
8

Same thing, less methods...

    var root_element = new RootElement("caption", (RootElement e) => {
        return new DialogViewController (e);
    });
James Furey
  • 178
  • 4
  • 9