开发者

Subclassing UIView and displaying multiple instances

I am trying to do the following:

  1. Display an instance of a custom UIView. This UIView subclass should load it's content from Interface Builder, because it shows stuff that I don't want to create by hand. My question is: How can I load from Interface Builder in a UIView subclass?

  2. I will eventually animate this v开发者_如何学Ciew out of the screen and release it. (I know how to do that :-) )

  3. GOTO Step 1, i.e creating a new instance of my UIView and display it.

Probably a noobish question, but I can't seem to figure it out. I would appreciate some help, Fabian


In iOS 4.0+, create an instance of UINib referencing your nib file (+nibWithNibName:bundle:), then instantiate the objects in the nib with -[UINib instantiateWithOwner:options:].

If you need to target iOS 3.x, too, call:

[[NSBundle mainBundle] loadNibNamed:owner:options:]

which returns an array of the objects in the nib file.


To load an interface from Interface Builder you need to use a UIViewController. If you don't use interface builder though, you can create a uiview subclass, create your interface, and then create instances of your class. For every class all you need to do is this:

MyView *view = [[MYView alloc] initWithFrame:theFrame];
MyView *secondView = [[MyView alloc] initWithFrame:theFrame];
//do stuff with the views
//release the views
[view release];
[secondView release];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜