gpt4 book ai didi

ios - 我的 View Controller 没有出现在屏幕上

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

我选择选项卡式应用程序模板。然后我添加了 CoolViewController,但它没有出现在屏幕上。怎么了?

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

CoolViewController *coolVC = [[CoolViewController alloc] init];
coolVC.view.frame = CGRectMake(0, 0, 320, 200);
coolVC.view.backgroundColor = [UIColor blackColor];
[self.window addSubview:coolVC.view];

[self.window makeKeyAndVisible];
return YES;
}

@interface CoolViewController : UIViewController
@end

最佳答案

您不应将 CoolViewController 添加到窗口,而应添加到 UITabBarController

你最终应该得到这样的结果:(注意:我还没有尝试过)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];

CoolViewController *coolVC = [[CoolViewController alloc] init];
coolVC.view.frame = CGRectMake(0, 0, 320, 200);
coolVC.view.backgroundColor = [UIColor blackColor];

self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2,coolVC, nil];
self.window.rootViewController = self.tabBarController;




[self.window makeKeyAndVisible];
return YES;
}

关于ios - 我的 View Controller 没有出现在屏幕上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11665199/

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