How to open a new window on button click in Cocoa Mac Application?

ShinuShajahan picture ShinuShajahan · Apr 5, 2011 · Viewed 38k times · Source

I want to know how to open a new window on button click in Cocoa Mac Programming. Help me. I am doing a mac application which needs to open a new mac window on particular button click.

Answer

iPhoneDv picture iPhoneDv · Apr 5, 2011

If you want to create a separate class for New Window, these are the steps:

  1. Create a class which is a sub class of NSWindowController e.g. NewWindowController
  2. Create a window xib for NewWindowController class.
  3. On button click code as:

    NewWindowController *windowController = [[NewWindowController alloc] initWithWindowNibName:@"You Window XIB Name"];
    [windowController showWindow:self];