【问题标题】:XAMARIN.IOS UITabBarController in some UIViewControllers一些 UIViewControllers 中的 XAMARIN.IOS UITabBarController
【发布时间】:2018-04-21 07:41:44
【问题描述】:

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

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

【问题讨论】:

    标签: ios uiviewcontroller xamarin.ios uinavigationcontroller tabbar


    【解决方案1】:

    制表符 -> 无制表符

    1. 推送时

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

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

    无标签 -> 标签

    先将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();
        }
    }
    

    并在Connection Page中更改它

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

    【讨论】:

    • ColeXia,非常适合隐藏!它就像一个魅力!但是反过来,这意味着有一个没有 TabBar 的 ViewController 并导航到另一个有 TabBar 的 ViewController,我该怎么办?更详细地说,连接 VC 没有 TabBar,在 appDelegate 中,我们有一个带有 UINavigationController 实例而不是 TabBar 的 RootViewController,当用户连接时,它将被导航到有一个 TabBar 的主页。你有什么想法吗?
    • 我认为最好的方法是从 AppDelegate 调用 _tabController = new TabController(); _window.RootViewController = _tabController; _window.MakeKeyAndVisible();
    • 但我不需要连接页面中的 TabBar !此外,我的 TabBar 中不存在 Connection !
    猜你喜欢
    • 2013-02-19
    • 1970-01-01
    • 2023-03-27
    • 2015-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    相关资源
    最近更新 更多