某些UIViewControllers中的XAMARIN.IOS UITabBarController

Ali*_*eza 3 tabbar uiviewcontroller uinavigationcontroller xamarin.ios ios

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

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

_tabController = new TabController();
_window.RootViewController = _tabController;
_window.MakeKeyAndVisible();
Run Code Online (Sandbox Code Playgroud)

如果我想要一个没有TabBar的视图,这里是appDelegate:

viewController = new ConnectionViewController();
_window.RootViewController = new UINavigationController(viewController);
_window.MakeKeyAndVisible();
Run Code Online (Sandbox Code Playgroud)

使用此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;
        }
    }
Run Code Online (Sandbox Code Playgroud)

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

我没有使用StoryBoard,我在Xamarin.iOS上编码.

Col*_*SFT 6

标签 - >无标签

  1. 当推

    ViewController2 vc2 = new ViewController2();
    vc2.HidesBottomBarWhenPushed = true; //add this line
    this.NavigationController.PushViewController(vc2, true);
    
    Run Code Online (Sandbox Code Playgroud)
  2. 当前

    this.PresentViewController(new ViewController2(), true, null);
    
    Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

没有标签 - >标签

首先将Connection Page设置为RootViewController,然后在需要时进行更改.

码:

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

并改变它 Connection Page

if(connected){
     AppDelegate app = UIApplication.SharedApplication.Delegate as AppDelegate;
     app.changeRootVC();
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述