Adding UITabBarController and have no NavigationController

那年仲夏 提交于 2019-12-12 10:10:04

问题


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.

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 will disappear
  2. navigating between viewControllers are not possible by this code :

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

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

_tabController = new TabController();
_window.RootViewController = _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;
        }
    }

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


回答1:


By wrapping your TabController in a UINavigationController.

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

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



来源:https://stackoverflow.com/questions/47159814/adding-uitabbarcontroller-and-have-no-navigationcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!