开发者

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

开发者 https://www.devze.com 2023-01-15 16:02 出处:网络
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 duri

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 yo开发者_StackOverflow社区u cannot easily use alternative to Xcode :)

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


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.


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消