by thought_alarm · 16y ago · 0 comments
That's understandable. Most other IDEs handle GUI development by simply mashing the view and the controller together into a single unit. That is fine if you just have a simple window with some buttons and text fields, but this approach quickly falls apart when applied to larger, more sophisticated software.
The Cocoa approach is different in that it completely separates the view (the NIB or XIB) from the controller(s). You're free to design your views, controllers, models as you see fit, and Interface Builder is there to help you realize that design.
But you actually have to design your software; XCode is not going to hold your hand and shoehorn you into a specific design, like most other IDEs.
A NIB is still a NIB. That's not going to change just because XCode and IB are now a single application. You will still have to design your software, and you will have to understand that design.
But software design is hard, so don't be discouraged. It will come with experience.
And this is why I am still soldiering on with my little app (which is really just a learning opportunity for me rather than anything I plan on capitalising on, so it's okay for me to make mistakes :). I'd like to learn how to do it better, and you're right, that comes with experience. That said, I think the new XCode will help people like me a bit more because it will probably be easier to see the links between the UI and the code. :)
I find the mechanism of connecting UI elements to outlets by dragging around to be gimicky and pointless.
Why can't the runtime auto-bind them by matching names? Doesn't ruby work this way?
There seems to be a bit of pointless work that you have to do to get a new controller and view connected and up-and-running.
Why can't the runtime auto-bind them by matching names? Doesn't ruby work this way?
The whole point of having the action/outlet system is that it provides a layer of indirection and lets you write less code. There's no need to write an event handler for a button to make it print a view. You just drag an action from your NSButton to your view, and set its selector to print:. The same goes for outlets.
I'm not sure what you mean by "auto-binding by matching names". The only way I could see that working, is if you gave the control and the target names, then inputted the action as (control name, target name, action). IMO this would be a lot more work than the current UI.
Well, I was referring more to linking IBOutlets as opposed to IBActions.
I think Visual Studio's way is superior - ie, from the UI Designer, you can autogenerate and link the action for a button as well as having the option to link an existing action.
You still have the problem of selecting the object owns the outlet. You may want to connect a text field to an outlet on a view nested down a few levels. You'd have to give both the text field and the view names, which again takes time and effort.
I think Visual Studio's way is superior - ie, from the UI Designer, you can autogenerate and link the action for a button as well as having the option to link an existing action.
I haven't used VS for quite a while. IIRC there is always a user class associated with the UI. This is not the case in Cocoa. It's common for file's owner to be, say, a plain NSWindowController, and there to be no user classes in the nib at all.
It's tempting to think of an "action" in Cocoa as being synonymous with a method. But this isn't the case. When you click a button, it doesn't directly call it's action on its target. The actual process is more complex, and provides a lot of room changing where the action message is sent. This is what makes insane magic that is first responders work.
But software design is ever improving, so don't be discouraged when the world passes you by because you've stuck with your antiquated ways.
This is a totally independent issue from view/controller separation. The right way to do UI development is through a layout language, like HTML/MXML, not through a GUI tool. The web world learned this a long time ago.