构建 xib Interface Builder 并将它们作为子视图加载到 iphone 中

发布于 2024-09-03 19:34:25 字数 120 浏览 3 评论 0原文

我想知道是否可以构建视图及其相应的 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.

thanks
Leonardo

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长途伴 2024-09-10 19:34:25

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

  1. 创建一个 MyView.m 视图文件,其中包含我所需的所有 IBOutlet
  2. 在界面生成器中构建一个 MyView.xib 视图,保留默认文件的所有者并设置视图作为 MyView.m
  3. 使用这段代码

     NSArray *xib = [[NSBundle mainBundle] loadNibNamed:@"MyView" 所有者:self 选项:nil];
      MyView * myView = [xib objectAtIndex:0];
      [自我添加子视图:myView];
    

它有效,实际上......

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文