At the moment my application mostly consists of a NSTableView bound to a CoreData Entity. Works like expected. In a next step I would like to extend my application to open another window to enter the details for adding content. I've designed the window in the interface builder (Another.xib) and added another ruby file to my project with the following content:
class AnotherController < NSWindowController
def windowNibName()
return "Another"
end
end
I added a NSObject in IB and set it's class to AnotherController. In my AppDelegate.rb I've added a method which gets called when selecting a menuitem:
def addItem(sender)
newWindow = AnotherController.alloc.init
newWindow.window.makeKeyAndOrderFront(self)
end
Now I can select the menu entry, which is calling addItem, which then opens the other window. This is working, but it doesn't feel right. Especially the AnotherController things seems a little bit odd to me. Is there a better way to do this?
From a code point of view what you have done here is correct, one controller per window (view), the rails paradigm is similar to cocoa.
But from a UI point of view this isn't very Mac like. Mac apps tend to have the list and detail views in panes in the same window, a split view. Look at mail.app, message list down one side, message details on the other side.
Just like rails, all your data should be represented by a model class so when you select additem you should create a model and add it to your list. In your code sample maybe you could make an initializer in AnotherController that takes a model, an empty one if it's a new item.
newWindow = AnotherController.alloc.initWithItem item
Should be pretty easy from there.
Henry