Do you have a dedicated UIViewController for each RootElement in MonoTouch.Dialog?

It's easy to create a layered menu structure using the nested RootElements in MonoTouch.Dialog , but how would you use a specific UIViewController to manage each root? The reason I want each RootElement have its own UIViewController is because I want to be able to easily manage things like a background image and switch the navigation bar from screen to screen, and this makes it trivial within the UIViewController .

+4
source share
2 answers

I think you are looking for this:

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

which allows you to create a UIViewController (for example, the DialogViewController that you configured, or a type inheriting from it).

This will allow you to embed your Element at the same time most of the control over the view and its controller.

UPDATE

Here's how to use it:

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

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

Then create your root elements using:

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

The above will give you the same thing:

  var root_element = new RootElement ("caption"); 

except that now you can customize the DialogViewController to your liking before returning it.

+9
source

Same thing, fewer methods ...

  var root_element = new RootElement("caption", (RootElement e) => { return new DialogViewController (e); }); 
+8
source

Source: https://habr.com/ru/post/1386828/


All Articles