gpt4 book ai didi

ios - TabBar 和导航 Controller

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:08:49 27 4
gpt4 key购买 nike

您好,我是 iOS 的新手,我正在尝试在基于 TabBar 的应用程序中显示导航 Controller 。

这是我得到的:H文件:

#import <UIKit/UIKit.h>



@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) UITabBarController *tabBarController;

@property (strong, nonatomic) UINavigationController *navigationController;

@end

M文件:

@implementation AppDelegate


- (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];
UIViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
UIViewController *viewController4 = [[FourthViewController alloc] initWithNibName:@"FourthViewController" bundle:nil];
UIViewController *viewController5 = [[FifthViewController alloc] initWithNibName:@"FifthViewController" bundle:nil];

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2,viewController3,viewController4,viewController5];



self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController5];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];

self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;

}

最佳答案

不是将 viewController5 添加到标签栏 Controller 的 View Controller ,而是添加导航 Controller 。

- (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];
UIViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
UIViewController *viewController4 = [[FourthViewController alloc] initWithNibName:@"FourthViewController" bundle:nil];
UIViewController *viewController5 = [[FifthViewController alloc] initWithNibName:@"FifthViewController" bundle:nil];

self.tabBarController = [[UITabBarController alloc] init];

self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController5];
self.tabBarController.viewControllers = @[viewController1, viewController2,viewController3,viewController4,self.navigationController];

self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;

}

关于ios - TabBar 和导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18842133/

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