objective-c – OS X如何指定启动视图控制器

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

相反,我编写了一个viewcontroller类BrowserViewController.
并在appdelegate中写下来

@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.
}

最佳答案 您可以在故事板中选择Is Initial Controller.

点赞