tags:

views:

357

answers:

4

Are there any good reasons why I should not use XIB / NIB files with an highly customized UI and extensive animations and super low memory footprint needs?

As a beginner I started with XIB. Then I figured out I couldn't do just about everything in them. It started to get really hard to customize things the way I wanted them to be. So at the end, I threw all my XIBs away and did it all programmatically.

So when someone asks me if XIB is good, I generally say: Yeah, if you want to make crappy boring interfaces and don't care too much about performance, go ahead. But what else could be a reason not to use XIB?

Am I the only iPhone developer who prefers doing everything programmatically for this reasons?

+3  A: 

Honestly I think it's a spectrum of convenience. If you are comfortable writing everything in code then go for it. If you design your project well then it should be about the same amount of work creating new windows, etc. But I know that a lot of people aren't as comfortable with the GUI world so nib/xibs work well there.

I honestly find myself using XIBs as a base quite often and editing them with code to get the specific look I want. Personal preference.

For a specific con on that point, views can be difficult to configure after loading them from a xib. When you have conflicting settings between IB and code that can be nasty to troubleshoot.

Here's a question for the list. What is the performance hit to using a xib? I thought they were a plus because they don't get loaded into memory until you need them. That said, that load time is longer which will slow your program down. Thoughts?

Staros
If you're worried about the performance of using XIBs over programmatic interfaces, you should read this: http://cocoawithlove.com/2010/03/load-from-nib-or-construct-views-in.html The gist is that yes, in some specific cases, programmatic construction of interfaces is faster, but in almost all cases there is little to no performance penalty.
mipadi
I agree with this. I haven't even bothered using XIBs because all of my experience in other languages helps me make things programmatically. When I get some spare time I will learn how Interface Builder works but until then I will do what I know.
MrHen
+3  A: 

I think that Interface Builder is one of the biggest assets of Mac (and by extension, iPhone) software development. GUIs are visual; why not create them using a visual interface? IB is flexible enough that you can lay out an interface using its "generic" components, and then subclass them where necessary. Sure, if you have a unique interface you're going to have to subclass a view class and perform custom drawing, but you can also lay out your interface in IB and then easily use the inspector to switch the class to your custom subclass.

mipadi
IB will not show you how your custom thing looks, so it's pointless.
dontWatchMyProfile
Sure, but it not seeing exactly what your custom things looks like but still being able to lay it out in a visual way is nicer than doing it completely programmatically. If you do it programmatically, you don't get to see what anything in your interface looks like *at all*. (And, if you have a custom element you use frequently, you can create an IB palette plugin for it.)
mipadi
That IB Palette thing seems interesting. However, if you have views that are actually transparent and make extensive use of -drawRect, and even dynamically adjust their frame, you're stuck with IB.
dontWatchMyProfile
A: 

One thing I found better about code is for the event connections on controls, when you search for uses of a method (message) you find them if they are coded and you don't find them if they were set in IB.

On the other hand laying out objects on a view is much easier in IB where you can see their size and positions. When you do that in code you have to guess at the size and origin settings and then run it and make adjustments, then run it again to see what it looks like.

progrmr
A: 

I save tons of time when dealing with UIControllers (UITabBarControllers, UINavigationControllers etc.) in the start up phase where all the navigation stuff is hooked up.

I just build X viewControllers with a accompanying XIB, throw in the stuff needed in IB, labels, images etc. This means that for almost any sort of app you can have a proof of concept up in a few hours. This is enough to justify spending some time learning the ins and outs of IB. Especially on the iPhone where you can have a ton of good UI ideas, but they all fail when they move from the Simulator to an actual device.

The best thing, in my mind, is to balance it out, if you find yourself using a lot of time doing the "change the frame 3 px -> compile -> ahh.. needs two pixels more -> change 2 px - compile -> ahh.. 1 more px" for something that could be done in IB, you will seriously start to waste time.

I start as above, but afterwards I often throw the XIBs away for custom stuff. The trick is to not spend hours on implementing versions of custom stuff in code over and over again, but figure out how it should be and do the custom stuff once:)

RickiG