一些UIViewControllers中的XAMARIN.IOS UITabBarController [英] XAMARIN.IOS UITabBarController in some UIViewControllers

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

问题描述

我有一个应用程序(Xamarin.IOS),它以没有TabBar的UIViewController(连接视图)开头.但是,当用户登录时,我想将自己创建的标签栏添加到其他视图中.反之亦然,当用户注销时,我想显示不带TabBar的连接视图.

I have an application (Xamarin.IOS) which start with a UIViewController (Connection view) with no TabBar. But when user Logged, I'd like to add the tabbar that I've created to other views. And vis-versa, when user logged out, I'd like to display the connection view without TabBar.

我知道,当我想在appDelegate中显示TabBar时,必须像这样初始化_window:

I know that when I want to display the TabBar, in appDelegate, I have to initialize _window like this :

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

如果我要不带TabBar的视图,则为appDelegate:

and if I want to have a view without TabBar, here is appDelegate:

viewController = new ConnectionViewController();
_window.RootViewController = new UINavigationController(viewController);
_window.MakeKeyAndVisible();

使用此TabController:

with this TabController :

public class TabController : UITabBarController
    {

        UIViewController tab1, tab2, tab3, tab4;

        public TabController()
        {
            tab1 = new UINavigationController(new ListViewController());
            tab1.Title = Texts.Home;
            tab1.TabBarItem.Image = UIImage.FromFile("Icons/Home@2x.png");

            tab2 = new UINavigationController(new OViewController(1));
            tab2.Title = Texts.Categories;
            tab2.TabBarItem.Image = UIImage.FromFile("Icons/Tag@2x.png");

            tab3 = new UINavigationController(new SearchViewController());
            tab3.Title = Texts.Search;
            tab3.TabBarItem.Image = UIImage.FromFile("Icons/Search@2x.png");

            tab4 = new UINavigationController(new BookmarkViewController(1));
            tab4.Title = Texts.Bookmarks;
            tab4.TabBarItem.Image = UIImage.FromFile("Icons/Favorite@2x.png");


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

            this.TabBar.BackgroundColor = UIColor.White;

            ViewControllers = tabs;
        }
    }

但是如何从具有TabBar的视图移动到没有视图的视图,反之亦然?

But how can I move from a view with TabBar to a view without and vis-versa ?

我不使用StoryBoard,而是在Xamarin.iOS上编写代码.

I don't use StoryBoard and I code on Xamarin.iOS.

推荐答案

选项卡->无选项卡

  1. 按下时

  1. When Push

ViewController2 vc2 = new ViewController2();
vc2.HidesBottomBarWhenPushed = true; //add this line
this.NavigationController.PushViewController(vc2, true);

  • 出现时

  • When Present

    this.PresentViewController(new ViewController2(), true, null);
    

  • 无标签->标签

    首先将连接页面"设置为RootViewController,然后在需要时将其更改.

    Set Connection Page as RootViewController at first, and then change it when you want to.

    代码:

    public partial class AppDelegate : UIApplicationDelegate
    {
        UIWindow window;
    
        public override bool FinishedLaunching (UIApplication app, NSDictionary options)
        {
            window = new UIWindow (UIScreen.MainScreen.Bounds);
    
            window.RootViewController = new UINavigationController(new ViewController1());
            window.MakeKeyAndVisible();
            return true;
        }
    
        public void changeRootVC()
        {
            window.RootViewController = new TabController();
        }
    }
    

    并在Connection Page

    if(connected){
         AppDelegate app = UIApplication.SharedApplication.Delegate as AppDelegate;
         app.changeRootVC();
    }
    

    这篇关于一些UIViewControllers中的XAMARIN.IOS UITabBarController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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