4

使用嵌套创建多级菜单结构很容易RootElementsMonoTouch.Dialog但是您将如何让一个特定的UIViewController管理每个根目录呢?我希望每个RootElement人都有自己UIViewController的原因是因为我希望能够轻松控制背景图像和在屏幕之间切换 NavigationBar 等内容,这样做在UIViewController.

4

2 回答 2

9

我想你正在寻找这个:

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退货之前根据自己的喜好自定义。

于 2011-12-17T16:28:39.067 回答
8

同样的事情,更少的方法......

    var root_element = new RootElement("caption", (RootElement e) => {
        return new DialogViewController (e);
    });
于 2012-02-15T04:42:53.373 回答