简体   繁体   中英

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

我是这个目标的新手 - 我想使用我按下按钮时创建的nib文件加载视图。不使用任何视图控制器..

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM