开发者

How to convert nib/xib to objective C code?

开发者 https://www.devze.com 2022-12-14 16:41 出处:网络
I am just wondering is there a way to convert nib/xib file to ojbective C code? I just want to find the开发者_运维问答 equivalent code to the nib/xib file (I\'ve tried nib2objc, seems the result is no

I am just wondering is there a way to convert nib/xib file to ojbective C code? I just want to find the开发者_运维问答 equivalent code to the nib/xib file (I've tried nib2objc, seems the result is not what I am after).

Actually I want to compile this example

http://developer.apple.com/iphone/library/samplecode/TableSearch/index.html

without nib/xib file (I want it exactly the same with original), any idea about doing this?


Check out nib2objc:

nib2objc converts NIB files (or XIB ones) into Objective-C code, including all the properties of each instance, the documented constructor calls, and also the view hierarchy.

nib2objc yourfile.xib > code.m


In the general case, I think the answer is no. Nibs are not code; they're archives of serialized objects. So what you're asking is, "Given a graph of arbitrary serialized objects, can I generate some source code that might create such a graph without using serialization?" Without special support for such a process in all classes involved, I don't see how you could.

It would probably be more beneficial to ask about what you actually need to accomplish rather than this specific way of doing whatever it is.


To all the 'There shouldn't be any reason to not use a nib/xib' type responses here, let me provide a concrete example as a counterpoint.

[iPhone OS 3.1.3, 3.2]

  1. iPhone OS apps have a limited amount of memory to work with. If you use too much your app is automatically terminated by the OS.
  2. Interface builder loads images referenced in a nib/xib into a cache using [UIImage imageNamed...], which uses up memory and does not automatically release that memory. There is also no way for you to request those images in that shared cache be released.
  3. Lay out some large images in nib/xib files (i.e. - backgrounds), in an app with multiple nib/xib files, and you will very quickly have an app which gobbles up memory quickly (3mbs per full size png background on iPad), that you have no control over releasing. Any doubts about this, check the documentation for [UIImage imageNamed] and do some googling to verify that is what is used.

That's a case for not using a xib/nib.


I think it makes sense to do this if you just want to create a starting point for a view that is created programmatically in a way that isn't easy or possible to do with Interface Builder. It is also convenient if you want to bundle the view hierarchy in to a static library so that it is fully self-contained. Ideally you want to use nibs if possible though. It will make internationalization easier. However you can still support internationalization with a strings file.

0

精彩评论

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

关注公众号