开发者

how to load a view using a nib file without using view controller

i am new to this objective-c i want to load a开发者_Go百科 view using nib file i created when i press a button .without using any view controller..


This is generally considered a bad idea if you don't know what you're doing, but if you really want to do this then there's 2 places to look, depending on what version of the OS you're developing for.

iOS 4

Look at UINib in the documentation. You can use this to load a nib fairly easily.

iOS 3.2 and earlier

Use NSBundle. There is a category, documented under the name "NSBundle UIKit Additions Reference", that adds a method -loadNibNamed:owner:options:. You can also use this on iOS 4.0 if you so desire.

In both cases, the owner object fills in the role of "File's Owner" in the nib, useful if you have actions or outlets specified on the owner. The method also returns an NSArray of all the top-level objects in the nib. Be careful, if you use this array you need to retain any of the objects that you want to keep, as the array (and all the objects) are returned autoreleased.


Try this. Should show you how to implement your UIView subclass.

http://markuzweb.blogspot.com/2011/05/subclassing-uiview-with-nib-file.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜