ios - 某些 UIViewController 中的 XAMARIN.IOS UITabBarController

标签 ios uiviewcontroller xamarin.ios uinavigationcontroller tabbar

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

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

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

如果我想要一个没有 TabBar 的 View ,这里是 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 的 View 移动到没有 TabBar 的 View ,反之亦然?

我不使用 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);
    

enter image description here

No Tab -> Tab

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

enter image description here

关于ios - 某些 UIViewController 中的 XAMARIN.IOS UITabBarController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47182764/

相关文章:

cocoa - Cocoa 文件操作的线程语义是什么?例如NSData 读/写方法

ios - 从 SecKey 对象获取 EC 私钥 PEM 字符串

iphone - 如何在Ipad中自定义SubView为PopuPView?

ios - Swift 计算属性不能在 init 中使用?

ios - 在为我的主视图加载数据时打开启动 View

objective-c - 在 View Controller 之间切换

ios - iOS(Xamarin)中带有图像和文本的UILabel

ios - 如何在 modaly swift 4 中呈现 ViewController

xamarin - 使用 Xamarin.UITest 测试我的 Xamarin.Forms iOS 应用程序 : The first test always fails

c# - 更改 iOS 设备会使 iOS 应用程序崩溃