gpt4 book ai didi

objective-c - OS X 如何指定启动 View Controller

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

我正在 mac 上开发一个简单的浏览器项目,我没有使用默认的 viewcontroller。

相反,我编写了一个 View Controller 类 BrowserViewController。并在 appdelegate 中写入 follow

@interface AppDelegate()
@property (nonatomic, strong) BrowserViewController *browserController;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
self.browserController = [[BrowserViewController alloc] init];

[self.window makeKeyWindow];
[self.window setContentView:self.browserController.view];
}

@end

但是当应用程序启动时,它会导致默认的 viewcontroller 而不是 BrowserViewController。我真的不知道原因。

谢谢你的帮助,我已经解决了这个问题。我的解决方案是这样的:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
//set the frame of the window fit to the device's frame
//
self.window = [[NSWindow alloc] initWithContentRect:[[NSScreen mainScreen] frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO ];

//
//
self.browserController = [[BrowserViewController alloc] init];


//set contentView
//
self.window.contentViewController = self.browserController;

//this is setting global backgroundColor of the window
//
self.window.backgroundColor = [NSColor whiteColor];

//this means the window is the window that will receive user interaction.
//
[self.window makeKeyAndOrderFront:self];
//[self.window makeKeyWindow];//NOTE: This is not working.
}

最佳答案

您可以在 Storyboard中选择Is Initial Controller

storyboard

关于objective-c - OS X 如何指定启动 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31454718/

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