将UIViewController更改为故事板中的UITableViewController? [英] Change a UIViewController to a UITableViewController inside a storyboard?

查看:130
本文介绍了将UIViewController更改为故事板中的UITableViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的故事板中提出了一个视图,我现在决定通过静态表格单元格显示其数据。

I've made a view in my storyboard which I've now decided I'd rather display its data via static table cells.

我无法使用 UIViewController中的静态表视图静态表视图仅在嵌入UITableViewController实例时有效)。所以,我需要以某种方式将现有的 UIViewController 转换为 UITableViewController 。我已经改变了.h文件的父级,但是还没有改变它。

I can't use static table views in a UIViewController (Static table views are only valid when embedded in UITableViewController instances). So, I need to convert my existing UIViewController to a UITableViewController somehow. I've changed the .h file's parent, but that hasn't done it.

还有另一种方法可以实现这一目标吗?我真的不想在故事板上创建一个新的VC并将所有内容移到一边,这是一个很大的麻烦。

Is there another way to get this going? I'd really rather not have to make a new VC in the storyboard and move everything over, it's a big hassle.

推荐答案

如果您希望静态单元格表​​视图不占用整个屏幕,那么使用容器视图是最简单的方法。从常规UIViewController开始,将容器视图(在对象列表中的普通UIView旁边)拖到其视图中。根据需要调整大小 - 故事板将自动提供连接到此容器视图的视图控制器,其中包含嵌入segue。删除该控制器,拖出一个表视图控制器,并从容器视图右键拖动到该表视图控制器,以创建一个新的嵌入segue。可以使用其childViewControllers属性从UIViewController访问此表视图控制器(相反,如果需要,可以使用parentViewController从表视图控制器访问UIViewController)。

If you want your static cell table view not to take up the entire screen, then using a container view is the easiest way to go. Start with a regular UIViewController and drag a container view (next to normal UIView in the object list) into its view. Resize it however you want -- the storyboard will automatically provide a view controller connected to this container view with an embed segue. Delete that controller, drag out a table view controller and right-drag from the container view to this table view controller to make a new embed segue. This table view controller can be accessed from the UIViewController with its childViewControllers property (and conversely, you can access the UIViewController from the table view controller with parentViewController if you need to).

这篇关于将UIViewController更改为故事板中的UITableViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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