本文介绍了MonoTouch.Dialog 中的每个 RootElement 都有一个专用的 UIViewController 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MonoTouch.Dialog 中使用嵌套的 RootElements 创建多级菜单结构很容易,但是您将如何拥有特定的 UIViewController> 改为管理每个根?我希望每个 RootElement 都有自己的 UIViewController 的原因是因为我希望能够轻松控制背景图像等内容,并在屏幕之间切换 NavigationBar 并执行此操作在 UIViewController 中是微不足道的.

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.

推荐答案

我认为您正在寻找这个:

I think you're looking for this:

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

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

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

这将让您继续嵌套 Element,同时提供对视图及其控制器的大部分控制.

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

更新

以下是如何使用它:

首先声明将创建 UIViewController 的方法.方法签名必须匹配Func,例如

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);

以上会给你相同的:

    var root_element = new RootElement ("caption");

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

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

这篇关于MonoTouch.Dialog 中的每个 RootElement 都有一个专用的 UIViewController 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 09:00