Some general MacRuby/Cocoa questions
Hi List, I'm new to the list and currently I'm struggling with MacRuby (or better: Cocoa). I've done some Ruby development (mostly Rails) in the past and think my knowledge about ruby is okay. But I've no idea about Cocoa and all I know about C are a few fragments C++ back from university... Currently I try to teach me some MacRuby/Cocoa with hacking together a small desktop application. Matt Aimonetti's book is already ordered and I hope it will arrive next week. I did some reading back when it was available for free on the net. So I already know some (small) things but actually I've some questions and I hope I'll find some answers on the list. If this is the wrong place to ask such questions, please let me know. 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? What are the next steps? What would be the best way to add another record to my CoreData based on the form values of my second window? I find it generally hard to imagine how to arrange a files in a larger MacRuby/Cocoa project. Is there some good reading on this topic? Regards, Timo -- twitter.com/orangeorb
On 12/11/2011, at 10:07 AM, Timo Springmann <timo@orangeorb.de> wrote:
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
Good morning, Am 11.11.2011 um 23:36 schrieb Henry Maddocks:
On 12/11/2011, at 10:07 AM, Timo Springmann <timo@orangeorb.de> wrote:
class AnotherController < NSWindowController def windowNibName() return "Another" end end
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.
To stay with your Mail.app example: when you create a new mail you do this in a new window (at least in Mail.app from Snow Leopard, don't know about Lion). As my data will have many attributes I would like to open a new window to enter all the details. I've also planned a "preview pane", where you can see the objects details when you select them in the TableView. I think one controller per window is fine. What I don't like about the code is the windowNibName method. Do I really have to do it this way? Or is there a better way to 'connect' my in IB designed window to my ruby contoller class? Regards, Timo -- twitter.com/orangeorb
On 12/11/2011, at 9:21 PM, Timo Springmann wrote:
I think one controller per window is fine. What I don't like about the code is the windowNibName method. Do I really have to do it this way? Or is there a better way to 'connect' my in IB designed window to my ruby contoller class?
I'm a bit rusty on thew stuff but I'm pretty sure that this method is optional as long as the NIB name can be inferred from the controller name, or you can connect it up in IB. Failing that just add a method to the base class that dynamically creates this method. It's Ruby after all, why not use it's flexibility? Henry
participants (2)
-
Henry Maddocks
-
Timo Springmann