一个 UIViewController 中的多种 UIView 类型 [英] Multiple UIView types in one UIViewController

查看:22
本文介绍了一个 UIViewController 中的多种 UIView 类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同一个笔尖中加载一个普通的 UIView、一个 UIWebView 和一个 UITableView.这可能在同一个 UIViewController 中吗?是否可以将多个 UIViewController 分配给同一个 Window?

I'd like to load a plain UIView, a UIWebView and a UITableView all in the same nib. Is that possible in the same UIViewController? Is it possible to assign multiple UIViewControllers to the same Window?

推荐答案

接近的事情是可能的.我最近回答了你的问题关于一个窗口中的多个视图;拥有多个视图控制器的方法非常相似,尽管它们确实需要单独的 nib 或 xib 文件.

Something close is possible. I recently answered your question about multiple views in one window; the approach for having multiple view controllers is very similar, although they do need separate nib or xib files.

具体做法如下:

  1. 实例化您需要的所有各种控制器
  2. 将每个控制器的视图添加到父视图或窗口,正如我在上一个问题中的回答

以编程方式,它看起来像(为您要添加的每个视图控制器重复):

Programmatically, it would look something like (repeated for each view controller you want to add):

// With some UIWindow *window
MyViewController *vc = [[[MyViewController alloc] 
                         initWithNibName:@"MyNib" bundle:nil] autorelease];
[window addSubview:vc.view];

请记住,您可能需要在添加之前调整视图的 frame 属性,具体取决于您希望将其放置在父视图或窗口中的位置.

Keep in mind you may need to adjust the frame property of the view before you add it, depending on where in the parent view or window you want to place it.

这篇关于一个 UIViewController 中的多种 UIView 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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