开发者

Build xib Interface Builder and load them as subview in iphone

what I would like to know if it's possible to build a view and its correspondent xib file. Then, in a generic 开发者_JAVA技巧controller, load this view programmatically and add as a subview to the current view.

This subview should act as a generic info box which can be loaded by many controller.

thanks Leonardo


I found solution myself, after looking at some stackoverflow thread. So I would like to share what I found and see if it's an acceptable solution. Basically this is what I did:

  1. create a MyView.m view file with all my required IBOutlet
  2. build a MyView.xib view in interface builder, leaving default file's owner and set view as MyView.m
  3. use this piece of code

      NSArray *xib = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil];
      MyView * myView = [xib objectAtIndex:0];
      [self addSubview:myView];
    

It works, actually...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜