0

I am building a Non-Document-based cocoa app that I want to behave as follows:

  • The main window contains a Table View with a list of items (backed by Core Data).
  • Each item should open in its own window
  • likewise, clicking on the new-item button should open a new-item window, with multiple such windows openable at the same time.

In my app delegate, which currently handles the table view, I implemented the following method to open a new Item Window:

-(IBAction)newItem:(id)sender {

    MyItemWindowController *itemController = [[MyItemWindowController alloc]initWithWindowNibName:@"MyItemWindowController"];

    [itemController showWindow:self];

}

The window does show, but it disappears almost immediately. If however, I instantiate a Window Controller that is an instance variable of my appDelegate, the window does stick around, but obviously, only one such window can remain open at any given time.

I would really like to have the mentioned functionality, but do not want to use the Document-based architecture, as I don't need to be able to save items as documents to disk.

Any suggestions? I know I must be missing something really basic, but I just cannot figure it out!

Arvindh
  • 77
  • 1
  • 5

1 Answers1

4

I'm guessing your window disappeared because of ARC (not too familiar with it, so I'm not certain if that's the reason), so just do what you said, but instead of having a MyItemWindowController as your instance variable, have an array as your instance variable that adds a new window controller whenever you need another new window.

TheAmateurProgrammer
  • 9,252
  • 8
  • 52
  • 71