gpt4 book ai didi

objective-c - 如何在 Cocoa 中将 View Controller 设置为 Root View ?

转载 作者:搜寻专家 更新时间:2023-10-30 19:41:28 25 4
gpt4 key购买 nike

我有一个 AppDelegatemainWindow.xib。我创建了另一个 viewController 并从 AppDelegate 调用,它运行良好。现在我怀疑是否可以将 View Controller 设置为根而不将其添加到 mainWindow.xib。是否必须用mainWindow.xib加载我们的 View ?

我这样调用 View Controller

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
self.view = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
[self.window.contentView addSubview:self.view.view];
self.view.view.frame = ((NSView*)self.window.contentView).bounds;
}

最佳答案

尝试使用

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

self.viewControllerObj = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

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

[self.window makeKeyAndVisible];
return YES;

}

关于objective-c - 如何在 Cocoa 中将 View Controller 设置为 Root View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18566566/

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