gpt4 book ai didi

ios - 如何在 AppDelegate 中为导航 View Controller 和标签栏 Controller 设置 rootViewController

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

我有这个问题。当我为 TabbarController 设置 rootViewController 时,它会正确显示。但是我为导航栏设置了另一个rootViewController,TabbarController将无法显示。有什么想法吗?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

self.window.rootViewController = [[DCTabBarController alloc] init];
DCTabBarController *tabBar = (DCTabBarController *)self.window.rootViewController;
[tabBar setSelectedIndex:2];

Map_ViewController *vc = [[Map_ViewController alloc] init];

UINavigationController *rootNav = [[UINavigationController alloc] initWithRootViewController:vc];
[rootNav.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbarBackImage"] forBarMetrics:UIBarMetricsDefault];
rootNav.navigationBar.tintColor = [UIColor whiteColor];
[rootNav.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, nil]];

LeftViewController *leftVC = [[LeftViewController alloc] init];

RightViewController *rightVC = [[RightViewController alloc] init];

XLSlideMenu *slideMenu = [[XLSlideMenu alloc] initWithRootViewController:rootNav];

slideMenu.leftViewController = leftVC;
slideMenu.rightViewController = rightVC;
self.window.rootViewController = slideMenu;

[self.window makeKeyAndVisible];

return YES;
}

应用 Adeel 解决方案后,输出如下。但标签栏中的项目不会相应显示。 enter image description here

最佳答案

这里要提到的一件重要的事情是应用程序的窗口只能有一个 rootViewController(当然)。就像我在评论中所说的那样,您可能想做这样的事情。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

Map_ViewController *vc = [[Map_ViewController alloc] init];

UINavigationController *rootNav = [[UINavigationController alloc] initWithRootViewController:vc];
[rootNav.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbarBackImage"] forBarMetrics:UIBarMetricsDefault];
rootNav.navigationBar.tintColor = [UIColor whiteColor];
[rootNav.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, nil]];

DCTabBarController *tabBar = [[DCTabBarController alloc] init];
[tabBar setViewControllers:@[rootNav]];
self.window.rootViewController = tabBar;

LeftViewController *leftVC = [[LeftViewController alloc] init];

RightViewController *rightVC = [[RightViewController alloc] init];

XLSlideMenu *slideMenu = [[XLSlideMenu alloc] initWithRootViewController:tabBar];

slideMenu.leftViewController = leftVC;
slideMenu.rightViewController = rightVC;
self.window.rootViewController = slideMenu;

[self.window makeKeyAndVisible];

return YES;
}

关于ios - 如何在 AppDelegate 中为导航 View Controller 和标签栏 Controller 设置 rootViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48456253/

25 4 0