Adding UITabBarController and have no NavigationCo

2019-05-27 01:42发布

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条回答
ゆ 、 Hurt°
2楼-- · 2019-05-27 02:26

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.

查看更多
登录 后发表回答