首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MonoTouch DialogViewController -为什么它必须放在UINavigationController的第一位?

MonoTouch DialogViewController -为什么它必须放在UINavigationController的第一位?
EN

Stack Overflow用户
提问于 2013-05-11 18:33:37
回答 1查看 1.1K关注 0票数 1

我想在UITabViewController中使用DialogViewController。

问题:嵌套元素不显示导航栏,因此无法返回。

当我将我的类(继承自DialogViewController)推送到UINavigationController时,行为是正确的。如果我在UITabViewController的选项卡中使用相同的类(即使使用底层的UINavigationController),那么行为就是错误的。

有人能帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2013-05-12 00:45:23

虽然这个问题没有通过一些代码样本得到帮助,但我做了一个小示例,希望能解决您的问题。在本例中,我使用了Xamarin.iOS附带的选项卡式应用程序模板,并将其命名为TabbingTest。

下面的代码放在AppDelegate中。更改FinishedLaunching方法以包含:

代码语言:javascript
复制
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
    window = new UIWindow (UIScreen.MainScreen.Bounds);

    var viewControllers = new UIViewController[]
    {
        CreateTabFor("Test", "first", new TestDialogController ()),
        CreateTabFor("Second", "second", new SecondViewController ()),
    };

    tabBarController = new UITabBarController ();
    tabBarController.ViewControllers = viewControllers;
    tabBarController.SelectedViewController = tabBarController.ViewControllers[0];

    window.RootViewController = tabBarController;
    window.MakeKeyAndVisible ();

    return true;
}

然后添加以下方法:

代码语言:javascript
复制
private int _createdSoFarCount = 0;

private UIViewController CreateTabFor(string title, string imageName, UIViewController view)
{
    var controller = new UINavigationController();
    controller.NavigationBar.TintColor = UIColor.Black;
    var screen = view;
    SetTitleAndTabBarItem(screen, title, imageName);
    controller.PushViewController(screen, false);
    return controller;
}

private void SetTitleAndTabBarItem(UIViewController screen, string title, string imageName)
{
    screen.Title = NSBundle.MainBundle.LocalizedString (title, title);
    screen.TabBarItem = new UITabBarItem(title, UIImage.FromBundle(imageName),
                                         _createdSoFarCount);
    _createdSoFarCount++;
}

创建一个名为TestDialogController的类,并将以下代码粘贴到其中。

代码语言:javascript
复制
using System;
using MonoTouch.Dialog;
using MonoTouch.UIKit;

namespace TabbingTest
{
    public class TestDialogController : DialogViewController
    {
        public TestDialogController (): base(UITableViewStyle.Plain,null,false)
        {       
            var root = new RootElement ("Tabbing test"){
                new Section (){
                    new RootElement ("First level", 0, 0) {
                        new Section (null, "This is the first level."){
                            new RootElement ("Second level", 0, 0) {
                                new Section (null, "This is the second level."){
                                    new BooleanElement ("Flipflops", false)
                                }
                            }
                        }
                    }}
            };

            this.Root = root;
        }
    }
}

现在运行应用程序。您可以看到,即使是嵌套的元素也会很好地显示在导航栏中。即使使用多级嵌套也是如此。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16496183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档