gpt4 book ai didi

ios - 跳出 UINavigationBar 后获取 UITabBar

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

我有一个 UINavigationBar,里面有一个 AuthenticateViewController。然后当用户在我的导航控件的右上角登录时,我想显示一个 UITabBar Controller 。我仍然在 appDelegate 中创建它吗?如何“突破”UINavigation Controller ?

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

// Add methods for layout of this view controller here

//1
AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
//2
self.managedObjectContext = appDelegate.managedObjectContext;

[self.navigationItem setHidesBackButton:YES];

// Now add the Sign In button
UIBarButtonItem *signinButton = [[UIBarButtonItem alloc] initWithTitle:@"Sign In" style:UIBarButtonItemStylePlain target:self action:@selector(signinButtonPressed:)];

self.navigationItem.rightBarButtonItem = signinButton;
}

- (void) signinButtonPressed:(UIBarButtonItem *) sender
{
// What goes here to start the UITabBars
}

最佳答案

登录后将您的TabBarController设置为rootViewController

您的按钮操作将如下所示:

UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = @[<your viewControllers>];

AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.window setRootViewController:tabBarController];

编辑:您可能不会使用 @[] 来创建数组。所以这里有一个解释:

UIViewController *viewController1 = [[UIViewController alloc] init];
UIViewController *viewController2 = [[UIViewController alloc] init];

// Two methods of adding item to array

// First method
NSArray *array = [NSArray arrayWithObjects:viewController1, viewController2, nil];

// or
NSArray *array = @[viewController1, viewController2];

tabBarController.viewControllers = array;

关于ios - 跳出 UINavigationBar 后获取 UITabBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23776239/

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