为MonoTouch.Dialog中的每个RootElement有一个专用的UIViewController



很容易在MonoTouch.Dialog中使用嵌套的RootElements创建多级菜单结构,但是如何让特定的UIViewController来管理每个根呢?我希望每个RootElement都有自己的UIViewController的原因是因为我希望能够轻松地控制背景图像和切换导航栏从屏幕到屏幕的事情,这样做是微不足道的从UIViewController内。

我想你在找这个:

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

允许您创建UIViewController(例如,您自定义的DialogViewController或从它继承的类型)。

这将让你继续嵌套你的Element,同时给大部分的控制视图和它的控制器。

可以这样使用:

首先声明创建UIViewController的方法。方法签名必须匹配Func<RootElement, UIViewController>,例如

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

接下来使用:

创建根元素
    var root_element = new RootElement ("caption", CreateFromRoot);

上面的结果与

相同
    var root_element = new RootElement ("caption");

现在您可以在返回DialogViewController之前根据自己的喜好自定义它

同样,方法更少…

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

相关内容

最新更新