views:

1693

answers:

5

I would prefer to create my interfaces programatically. Seems as if all the docs on Apple Developer assume you're using Interface Builder. Is it possible to create these interfaces programatically, and if so where do I start learning about how to do this

I thought the relevant document for this, if possible would be in this section: http://developer.apple.com/referencelibrary/Cocoa/idxUserExperience-date.html

+16  A: 

I would prefer to create my interfaces programatically.

Why? Interface Builder is easier and faster. You can't write a typo by drag and drop, and you don't get those oh-so-handy Aqua guides when you're typing rectangles by hand.

Don't fight it. Interface Builder is your friend. Let it help you.

If you insist on wasting your own time and energy by writing your UI in code:

Not document-based (generally library-based, like Mail, iTunes, iPhoto): Create a subclass of NSObject, instantiate it, and make it the application's delegate, and in the delegate's applicationDidFinishLaunching: method, create a window, populate it with views, and order it front.

Document-based (like TextEdit, Preview, QuickTime Player): In the makeWindowControllers method in your subclass of NSDocument, create your windows (and populate them with views) and create window controllers for them, making sure to send yourself addWindowController: for each window controller.

Peter Hosey
Amen. I used to be of that "write everything myself" mindset. Then I learned what it meant to meet project deadlines. It's a real eye-opener.
unforgiven3
I triple that. Interestingly, I've had a few developers coming from the Java world recently also say they prefer to code the interface themselves... right up until they understood that IB doesn't generate any code and doesn't need to. Guess the IDE-generated swing code really sucks :-)
Jarret Hardie
"You can't write a typo by drag and drop" actually, I've discovered, you can.. I've caused weird application-crashing errors by accidently dragging to the wrong outlet or binding. Interface Builder is okay, but it's not foolproof (not to say creating interfaces by hand is any better, but if nothing else the errors in ObjC are a bit more.. obvious)
dbr
btw, Apple avoids using IB too: http://lapcatsoftware.com/blog/2008/10/20/working-without-a-nib-part-7-the-empire-strikes-back/
yairchu
yairchu: Huh? That link doesn't appear to support your claim. Care to explain further?
Peter Hosey
A: 

Hmmm... I am trying to make an API that is cross platform. I don't care if anybody calls me crazy or stupid, but it can be done. I would like to use cocoa (instead of glut), as cocoa is native for the mac. For windows, the windows API. For the mac side, I need to do it programmatically. Will not listen to any criticism, so don't say anything. Any answers, please reply.

Huh? (Oh, I need 15 characters)
mmc
You might try posting this as an actual question, instead of an irrelevant answer to someone else's question.
Peter Hosey
Downvoted for hijacking a question, and to top it off, not being polite.
blwy10
+3  A: 

I like the question, and I'd also like to know of resources for going IB-less. Usefulness (the "why") is limited only by imagination. Off the top of my head, here are some possible reasons to program UIs explicitly:

  • Implementing a better Interface Builder.
  • Programming dynamic UIs, i.e., ones whose structure is not knowable statically (at compile/xcode time).
  • Implementing the Cocoa back-end of a cross-platform library or language for UIs.

There is a series of blog posts on working without a nib and a recent description by Michael Mucha on cocoa-dev.

Conal
A: 

In fact IB becomes totally unusefull when you start to write your own UI classes. Let say that you create your own button that use an skin system based on a plist. Or you create an dinamic toolbar that load and unload items based on user selection.

IB doesn't accept custom UI elements, so more complex UI can't use him. And YES you will want to do more complex things that the UIKit gives you.

Paulo
You can definitely create your own IB elements. http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/IBPlugInGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40004323
kubi
Light at end of the tunnel!! Works for IB on iPhone too?
Paulo
Nice post about this subject: http://cocoawithlove.com/2009/07/custom-views-in-interface-builder-using.html . And i'm not sure yet, but this technique doesn't work on iPhone yet. :(
Paulo
+1  A: 

As a completely blind developer I can say that IB is not compatible with VoiceOver (the built-in screen-reader on OS X).

This means that without access to robust documentation on using Cocoa without IB I cannot develop apps for OS X / iPhone in Cocoa, which means I (ironically) cannot easily develop apps that are accessible to the blind (and all others) on OS X / iOS.

My current solution, which I would prefer not to use, is Java + SWT, of course this works for OS X, not so much for iOS.

Everett Zufelt
I think the documentation is there. It's just not in the howto's which sucks. :/
apphacker