gpt4 book ai didi

ios - 在 TabBarController 和 ViewController 之间切换的最佳方法

转载 作者:行者123 更新时间:2023-11-29 11:00:25 25 4
gpt4 key购买 nike

我一直在尝试一个带有初始登录屏幕的应用程序,然后进入 TabBarController
我想知道执行此操作的最佳方法是什么,我们将不胜感激。我试过了,但无法从 ViewController 切换到 TabController

最佳答案

我不确定这是最好的方法,但它又快又脏而且有效。在您的 applicationDidFinishLaunchineWithOptions: 方法中呈现模态视图 Controller 。您应该将 @selector 替换为更适合您想要执行的操作的内容。背景颜色仅用于效果。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;


[self.window makeKeyAndVisible];


// ***** The relevant code *****
UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[[viewController view] setBackgroundColor:[UIColor redColor]];
UIButton *dismissButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[dismissButton setFrame:CGRectMake(10, 10, 300, 44)];
[dismissButton setTitle:@"Dismiss" forState:UIControlStateNormal];
[dismissButton addTarget:[self tabBarController] action:@selector(dismissModalViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
[[viewController view] addSubview:dismissButton];
[[self tabBarController] presentViewController:navigationController animated:NO completion:nil];

return YES;
}

我通常不想将这种代码放在应用程序委托(delegate)中,但如果它是一次性的,例如登录详细信息,也许没问题。

enter image description here

关于ios - 在 TabBarController 和 ViewController 之间切换的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16112791/

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