一些UIViewControllers中的XAMARIN.IOS UITabBarController

我有一个应用程序(Xamarin.IOS)开始与UIViewController(连接视图)没有TabBar。 但是,当用户login,我想添加我创build的标签栏到其他视图。 反之亦然,当用户注销时,我想显示连接视图没有TabBar。

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

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

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

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

与此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的视图移动到一个没有,反之亦然?

我不使用StoryBoard,我在Xamarin.iOS上编码。

Tab – > No Tab

  1. 推时

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

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

在这里输入图像说明

无标签 – >标签

首先将连接页面设置为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(); } } 

并在Connection Page更改它

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

在这里输入图像说明