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

查看:21
本文介绍了将 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 旁边)拖到它的视图中.根据您的需要调整它的大小——故事板将自动提供一个连接到这个容器视图的视图控制器,并带有嵌入转场.删除那个控制器,拖出一个表视图控制器,然后从容器视图中右键拖拽到这个表视图控制器来创建一个新的嵌入转场.这个表视图控制器可以通过它的 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天全站免登陆