UIViewController 中的 UITableViewController [英] UITableViewController inside a UIViewController

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

问题描述

我是 iOS 和 Objective-C 的新手,我在理解控制器的工作原理方面遇到了一些麻烦.

I'm new to iOS and objective-C and I'm having some trouble in understanding how controllers work.

在我的代码中,我有一个 UIViewController(我的自定义控制器由故事板分配),在它里面,连同其他对象,我想要一个由不同控制器处理的表.这样做的正确方法是什么?

In my code I have a UIViewController (with my custom controller assigned by storyboard) and inside it, together with other objects, I want to have a table handled by a different controller. What is the right way to do this?

推荐答案

您可以使该表视图控制器成为 UIViewController 的子视图控制器.

You can make that table view controller a child view controller of your UIViewController.

在故事板中,您可以通过将容器视图拖到控制器视图中来轻松完成此操作,这将自动为您提供一个子视图控制器.

In the storyboard, you can do this easily by dragging a container view into your controller's view, and that will give you a child view controller automatically.

你会想要:

  • 删除它给你的子视图控制器(它只是一个 UIViewController)
  • 拖出一个表格视图控制器
  • 控制从容器视图拖动到表视图控制器
  • 选择嵌入".

如果您需要从 UIViewController 获取对此表视图控制器的引用,您可以在 prepareForSegue 中执行此操作——表视图控制器将是 segue 的目标视图控制器,并且 prepareForSegue 将在控制器实例化后立即调用.

If you need to get a reference to this table view controller from the UIViewController, you can do that in prepareForSegue -- the table view controller will be the segue's destination view controller, and prepareForSegue will be called right after the controllers are instantiated.

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

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