本文介绍了添加 UITabBarController 并且没有 NavigationController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我是 Xamarin.IOS 的新手,我想问一个问题.我已经按照 这个例子在 Xamarin.IOS 项目中添加 UITabBarController.

As I'm new in Xamarin.IOS, I'd like to ask a question.I've followed this example for adding UITabBarController in a Xamarin.IOS project.

当我通过 TabController 的实例初始化 RootViewController 时,它工作正常并且我拥有所有选项卡.但是我的 NavigationController 设置为 null !这意味着:

When I initialized RootViewController by an instance of TabController, it works fine and I have all tabs.BUT my NavigationController set null ! it means that :

  1. NavigationItem 会消失
  2. 此代码无法在 viewController 之间导航:

  1. NavigationItem will disappear
  2. navigating between viewControllers are not possible by this code :

this.NavigationController.PushViewController(new ProfileViewController(), true);

因为 NavigationController 为空!这是我在 AppDelegate 中的代码:

because the NavigationController is null !Here is my code in AppDelegate:

_tabController = new TabController();
_window.RootViewController = _tabController;

和我的 TabController :

and my TabController :

public class TabController : UITabBarController
    {

        UIViewController tab1, tab2, tab3, tab4;

        public TabController()
        {
            tab1 = new HomeViewController();
            tab1.TabBarItem.Image = UIImage.FromFile("Icons/Home.png");

            tab2 = new TagCategoryViewController(null, null, 1, null);
            tab2.TabBarItem.Image = UIImage.FromFile("Icons/Tag.png");

            tab3 = new SearchViewController();
            tab3.TabBarItem.Image = UIImage.FromFile("Icons/Search.png");

            tab4 = new ProfileViewController();
            tab4.TabBarItem.Image = UIImage.FromFile("Icons/Home.png");

            var tabs = new UIViewController[] {
                tab1, tab2, tab3,tab4
            };

            ViewControllers = tabs;
        }
    }

另外,我有很多 UIViewControllers 并且我以编程方式完成所有这些并且我不使用 StoryBoard !

In additional, I have lots of UIViewControllers and I do all of them programmatically and I dont use StoryBoard !

推荐答案

通过将 TabController 包装在 UINavigationController 中.

By wrapping your TabController in a UINavigationController.

_tabController = new TabController();
_window.RootViewController = new UINavigationController(_tabController);

这样 NavigationController 属性就不会为空,导航就可以完成了.

This way NavigationController property won't be null and navigation can be done.

这篇关于添加 UITabBarController 并且没有 NavigationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 08:33