gpt4 book ai didi

iOS Xamarin 将 tabBar 推到导航 Controller 上

转载 作者:行者123 更新时间:2023-11-29 05:16:01 24 4
gpt4 key购买 nike

我有一个登录屏幕,用户登录后,我希望选项卡位于底部,并在顶部有一个导航栏。我可以选择其中之一,但不能同时获得两者。可能吗?

    partial void LoginButton_TouchUpInside(UIButton sender)
{
// push tab controller
tabController = new MyTabBarController();
navController = new UINavigationController();
navController.PushViewController(tabController, true);
}

应用程序委托(delegate):

public override bool FinishedLaunching(UIApplication application, 
NSDictionary
launchOptions)
{
// Override point for customization after application launch.
// If not required for your application you can safely delete
this method

//set root view controller
Window = new UIWindow(UIScreen.MainScreen.Bounds);

//Create navigation controller and tab controller
UINavigationController navctrl = new
UINavigationController(new
StartViewController());
MyTabBarController tabController = new MyTabBarController();

Window.RootViewController = navctrl;

Window.MakeKeyAndVisible();

return true;
}

最佳答案

您需要先将 UINavigationController 设置为 RootViewController ,然后将 TabBarController 添加到 UINavigationController ,然后就可以工作了。如下:

Window = new UIWindow(UIScreen.MainScreen.Bounds);

// Set up the first View Controller
var vc1 = new UIViewController();
vc1.View.BackgroundColor = UIColor.Orange;
vc1.TabBarItem.Title = "Orange";

// Set up the second View Controller
var vc2 = new UIViewController();
vc2.View.BackgroundColor = UIColor.Purple;
vc2.TabBarItem.Title = "Purple";

// Set up the Tab Bar Controller to have two tabs
var tabBarController = new UITabBarController();
tabBarController.ViewControllers = new UIViewController[] {vc1,vc2};

var registerController = new UINavigationController(tabBarController);

Window.RootViewController = registerController;
Window.MakeKeyAndVisible();

顺便说一句,从 iOS 13 开始,您最好在 SceneDelegate.cs 的方法(WillConnect)中编写代码来设置 RootViewController 。

public void WillConnect (UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
{
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see UIApplicationDelegate `GetConfiguration` instead).

UIWindowScene windowScene = new UIWindowScene(session, connectionOptions);

// Set up the first View Controller
var vc1 = new UIViewController();
vc1.View.BackgroundColor = UIColor.Orange;
vc1.TabBarItem.Title = "Orange";

// Set up the second View Controller
var vc2 = new UIViewController();
vc2.View.BackgroundColor = UIColor.Purple;
vc2.TabBarItem.Title = "Purple";

// Set up the Tab Bar Controller to have two tabs
var tabBarController = new UITabBarController();
tabBarController.ViewControllers = new UIViewController[] {vc1,vc2};

var registerController = new UINavigationController(tabBarController);
this.Window = new UIWindow(windowScene);
this.Window.RootViewController = registerController;
this.Window.MakeKeyAndVisible();
}

关于iOS Xamarin 将 tabBar 推到导航 Controller 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59182148/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com