不使用StoryBoard的xamarin.ios中的UITabBarController [英] UITabBarController in xamarin.ios without using StoryBoard

查看:102
本文介绍了不使用StoryBoard的xamarin.ios中的UITabBarController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此帖子中继续我的问题/a>,我想发布一个完整的问题,这将是很多xamarin.ios开发人员的问题.

In continue of my question in this post, I want to post a complete question which will be a question lots of xamarin.ios developers.

我的请求在所有UIViewControllers中都具有TabBar.因此,据我所知,有两种方法可以实现它.

My request is having TabBar in ALL UIViewControllers. So, as I know, there are two ways to realize it.

第一:

appDelegate->设置RootViewController:TabController-> UVC1

appDelegate -> set RootViewController : TabController -> UVC1

在这种情况下,我有 NULL ,并且没有NavigationItem.并在

in this case, I have NULL NavigationController and I'll have no navigationItem. and in

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

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

NavigationController为null会出错.

It makes error that NavigationController is null.

这是我在AppDelegate中的代码:

Here is my code in AppDelegate:

_tabController =新的TabController(); _window.RootViewController = _tabController;

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

和我的TabController:

and my TabController :

公共类TabController:UITabBarController {

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;
    }
}

第二种方式:

RootViewController-> navigationController-> TabController-> UVC1-> 新的UVC2->没有标签栏!

RootViewController -> navigationController -> TabController -> UVC1 -> new UVC2 -> no tab bar !!

在这里,一切听起来都不错,但是当我导航到Tabs中不存在的新UIViewController时,TabBar将消失!

Here, everything sounds good, but when I navigate to new UIViewController which is not present in Tabs, the TabBar will diappear !

代码是:

_tabController = new TabController();
var navigationController = new UINavigationController(viewController);
_window.RootViewController = new UINavigationController(_tabController);

我该怎么办?任何的想法?

What can I do ? Any idea?

我不使用StoryBoard!

I don't use StoryBoard !

推荐答案

通过用UINavigationController包装所有UIViewController,您可以启用所需的行为,但是请确保从NavigationBar开始删除TabBarController.将与您的视图中的NavigationBar重叠.

By wrapping all your UIViewController with UINavigationController you can enable the behaviour you want, but make sure that you remove TabBarController since the NavigationBar will overlap the NavigationBar from your Views.

_window.RootViewController = _tabController;

您的看法:

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

这篇关于不使用StoryBoard的xamarin.ios中的UITabBarController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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