From: Brian M. <ma...@ex...> - 2009-10-15 22:22:08
|
I can't answer all your questions since I don't know the sources or context. I did write a book on RubyCocoa (/Programming Cocoa with Ruby/), which I hope would help you... On Oct 5, 2009, at 3:47 AM, Christian Aust wrote: > () Where do I find documentation on ib_outlet and ib_action? Is > ib_outlets just an alias or a different method? What is kvc_accessor > being used for? A quick search didn't find any great explanations of outlets and actions, so in brief: an outlet is just an instance variable. An action is just a method. They're declared so that Interface Builder can recognize them and make them available in its inspector. (And for documentation.) Then you can connect outlets to graphical user interface objects just by dragging. That sets the instance variable. You can connect actions in the same way. After that, the UI object will do whatever it does by calling the method. For example, if you connect an action to a button, clicking the button will call the method. ib_outlet and ib_outlets are the same thing. > () Some sources say that I do need to "require 'osx/cocoa'", while > others don't. Some say I do need to explicitly declare each action, > while others don't. How is it supposed to be? As far as I know, you have to require it. (Normally done in rb_main.rb.) Explicitly declare with ib_action? You don't have to, but then IB won't automagically notice it. But you can manually tell IB that it exists. > () The message awakeFromNib seems to be sent twice, the first time > none of my outlets being available. Why is that? Is there more than > one instance of my controller class? If the program is set up correctly, awakeFromNib should only be sent after all the outlets are connected to their objects. It shouldn't be called twice. Objects you create with Interface Builder should only have one instance. > () Input entered into a NSTextField should be mapped to an instance > variable. Is it best practice to use an action that updates the > instance variable when the user finishes typing, or would I do that? An NSTextField is probably connected to both an outlet and an action. If your code wants to put text in the NSTextField, it uses the outlet. When the user hits <Return> in the text field, the action is called. (And then it can use the outlet to look at the text.) ----- Brian Marick, independent consultant Mostly on agile methods with a testing slant Author of _Programming Cocoa with Ruby_ www.exampler.com, www.exampler.com/blog, www.twitter.com/marick |