views:

295

answers:

4

I'm very new to Cocoa for MacOSX, but I can't help but feel like I'm constantly fighting Interface Builder.

My current situation is that I'm building an app that will have several custom controls and views. I started building the app in Interface Builder because it was initially very easy to drag things around and get them into the correct spots with the proper colors and the correct autosizing rules. However the time has come to start building my custom controls and views - which I can't nicely represent in Interface Builder without going through the work of building an IBPlugin! The only other option I know of it is to have an Interface Builder document that includes a bunch of "Custom Views" all over the place with only their class changed. It suddenly seems pointless to even bother with IB - especially in light of that fact that these controls and views will have properties such as color that need to be set - just like the other views and controls already in the IB document. So now I've got visualization properties being set in two disconnected places and seems to counter one of the potential advantages of IB which is making it relatively easy to tweak the UI of the app without digging into code.

I'm also faced with a situation where a few controls change properties (such as colors) based on data or current selections. So now I have initial default colors of the control specified in Interface Builder, but I have to specify the data-driven colors in code? Once again Interface Builder seems to cause me to have to split some presentation settings between it's world and the code. I suppose it's possible to solve this somewhat with a complex plugin that knows about my data or states or whatever, but it seems like I'd end up maintaing a ton of support code that exists just so the Interface Builder experience remains "right."

Something else that I often see mentioned is how easily IB allows you to define bindings between components. "You can do it without writing any code!" Again, I may be missing something, but binding one property to another is a single line of code as far as I can tell. Is setting a couple properties in a box in IB really better than writing that one single line of code? And why is it better to put what amounts to application logic in the presentation layer's specification?

Like I said at the open, I'm pretty new to this Cocoa stuff, but I feel like either I'm missing something very important about how to use Interface Builder, or it's designed primarily for trivial demo applications with a high "wow" factor.

+1  A: 

My first iPhone program, available for sale, as well as my second one under development do not use Interface Builder. I like having it all in the code so I can understand what is happening and so that I can use version tracking to track all changes.

So far as I know it comes down to a matter of preference. There are Cocoa books out there which use both styles (IB and no IB).

Devin Ceartas
I did that as well on the iPhone - partly because when I started iPhone development, IB had almost no support for it anyway so I never bothered using it. However the OSX world seems very IB-centric from what I've run across, so it seemed that was simply "how it was done." I guess I'm trying to find out if that perception is really true or not. You indicate that there's books that swing both ways on this, so that's reassuring that perhaps I wouldn't lose anything significant if I just used IB to manage the menubar and left everything else to the code.
Sean
Negative votes? Who the hell has the ego to dish out negative points for a subjective question to which I answer with honest experience and my opinion?! Gesh, rough crowd.
Devin Ceartas
yeah.. no kidding.. even my original question got negative votes despite generating several interesting answers!
Sean
+6  A: 

I find that Interface Builder is excellent for getting the generic layout of an app. It's also wonderful for things like bindings (on the Mac). However, there's no way you're going to create Delicious Library using Interface Builder. The more complex your interface, the more code you'll have to write.

Dave DeLong
+2  A: 

Jeff LaMarche (of iPhone development fame) wrote an excellent article about why IB is a good choice to use, even if it doesn't 'seem' the right route once you get past basic tutorials. I had given up on IB for similar reasons to you, but the article inspired me to keep working with it, and it really does end up being the right solution, even though it goes against the geek tendency to not allow too leaky abstractions.

refulgentis
That article seemed to be mostly a case of, "use it because I'm telling you it's awesome." There was really only one argument (that I noticed) that was specifically listed which was that since it doesn't result in code, there's less code to debug. It sounds nice, but I don't know I buy that entirely. Setting a couple bindings up or some frame rectangles takes clicks and typing in IB or a few lines in Objective-C. It's not like those lines of code will suddenly change themselves later and bugs will magically appear there.
Sean
+5  A: 

Interface Builder can take a little getting used to. But, as has been previously stated, the more you use it, the better it is. Sure, custom views can be done in code, but IB is a standard for a reason. Mac apps are held to certain standards of UI quality by the community, which are much higher than the UI standards for other platforms. IB makes it much easier to conform to those standards than doing everything in code, with no visual reference.

And you don't have to do everything in code to have your UI in version control. All of my Cocoa projects live in their own git repository with includes nib/xib files.

So give IB a chance. It only gets easier the more you use it.

alesplin
It's not that hard to use IB. The issue is if it makes sense or not that it seemingly results (at least for this project) in having a lot of different properties set in different ways - some in IB, some in code, some data-driven, etc. because IB can't support my custom views and things without writing a plugin and a bunch of support code for it. :/
Sean