添加UITabBarController并且没有NavigationController [英] Adding UITabBarController and have no NavigationController

本文介绍了添加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为null! 这是我在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中.

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

这样,NavigationController属性将不会为null,并且可以完成导航.

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆