构建xib Interface Builder并将其作为子视图加载到iphone中 [英] Build xib Interface Builder and load them as subview in iphone

查看:107
本文介绍了构建xib Interface Builder并将其作为子视图加载到iphone中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以构建视图及其对应的xib文件。
然后,在通用控制器中,以编程方式加载此视图并将其作为子视图添加到当前视图。

what I would like to know if it's possible to build a view and its correspondent xib file. Then, in a generic 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.

谢谢
Leonardo

thanks Leonardo

推荐答案

在查看了一些stackoverflow线程后,我自己找到了解决方案。所以我想分享我发现的内容,看看它是否是可接受的解决方案。
基本上这就是我所做的:

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. 创建 MyView.m 查看包含我所需的所有IBOutlet的文件

  2. 在界面构建器中构建一个 MyView.xib 视图,将默认文件的所有者和设置视图保留为 MyView.m

  3. 使用这段代码

  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...

这篇关于构建xib Interface Builder并将其作为子视图加载到iphone中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆