user310291
user310291

Reputation: 38190

Is it possible to build an iphone view WITHOUT using Interface Builder?

So Interface Builder does things to save time but what if I want to do without it ? In C# all code generated is clear and understandable, in interface builder this is hidden so I'd like at least during learning phase do things from scratch: any sample code to do so ?

Seems Apple makes things very hard so as you cannot easily use alternative to Xcode :)

http://cocoawithlove.com/2009/02/interprocess-communication-snooping.html

Upvotes: 1

Views: 1107

Answers (4)

hotpaw2
hotpaw2

Reputation: 70703

Interface builder doesn't generate code to build a UI object. It creates a compressed xib data object which the iOS runtime "uncompresses" (does some housecleaning) into your pre-built object.

The paradigm is to actually think of you objects as objects in their own right, and not just the results of code execution. e.g. what you would end up with if you could "Make it so." without writing any code.

Upvotes: 1

dommer
dommer

Reputation: 19810

This blog post shows you how to get started with a nibless iPhone project.

And you might want to look at this SO question to learn about creating views (e.g. a UIButton in this case) programmatically.

Upvotes: 1

Stephen Darlington
Stephen Darlington

Reputation: 52565

Interface Builder doesn't work in the same way as Visual Studio. It doesn't generate code, instead it generates "raw" object instances. In this sense it's not possible to see the code because there is no code generated.

One option nib2objc to convert your interfaces to code, though I'm not sure how readable that would be. As noted above, this is not the code that would be executed by your iPhone.

Upvotes: 2

Codo
Codo

Reputation: 78855

Yes, you can build a view without IB. Just allocate and initialize a view or a control and set its properties, e.g.:

UITextField *tf= [[UITextField alloc] initWithFrame: CGRectMake(24.5, 65, 270, 30)];
tf.delegate = self;
tf.textAlignment = UITextAlignmentCenter;
tf.autocorrectionType = UITextAutocorrectionTypeNo;
tf.autocapitalizationType = UITextAutocapitalizationTypeNone;
[self.view addSubview: tf];

But IB does not hide any generated code from you because it doesn't generate any code at all. Instead, it creates object instances and serializes them into a XIB or NIB file.

Upvotes: 3

Related Questions