OS X How to Assign a Launch View Manager

I am developing a simple browser project on mac, I did not use the default view manager.

Instead, I am writing the viewcontroller class BrowserViewController. and write in 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

But when the application starts, it leads to the default view, and not to the BrowserViewController. I really don't know the reason.

Thanks for the help, I solved this problem. My solution is this:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
//set the frame of the window fit to the device 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.
}
+4
source share
3 answers

You can choose Is Initial Controllerfrom the storyboard.

storyboard

+2
source

It looks like what you are looking for (inside the didFinishLaunchingWithOptions method):

self.browserController = [[BrowserViewController alloc] init];
[self.window setRootViewController: self.browserController];
[self.window makeKeyAndVisible];
0
source

:

iOS, . , - ..:)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //set the frame of the window fit to the device frame
    //
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    //what you have above is correct
    //
    self.browserController = [[BrowserViewController alloc] init];

    //you can also directly set it like
    //
    BrowserViewController *mainView = [[BrowserViewController alloc] init];

    //this is the most important, you need to set the window rootViewController
    //
    self.window.rootViewController = mainView;

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

    //this means the window is the window that will receive user interaction.
    //
    [self.window makeKeyAndVisible];

    return YES;
}

, . !:)

0

Source: https://habr.com/ru/post/1598219/


All Articles