如何使用故事板将 UITableView 添加到多个子视图之一 [英] How to add UITableView to one of several subviews using storyboard

查看:45
本文介绍了如何使用故事板将 UITableView 添加到多个子视图之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个 UIView 的 UIViewController.在导航栏中,当按下一个按钮时会显示一个 UIViews,当按下另一个按钮时会显示另一个 UIView.我想在其中一个视图上放置一个 UITableView.但是,UITableView 需要 UIViewController 使用 UITableViewDelegate 和 UITableViewDataSource.为包含 UTTableView 的 UIView(子视图)实现了此功能后,当我单击不包含表格的另一个视图的按钮时,出现错误并且应用程序发出吱吱声.

I have one UIViewController with two UIViews on it. In the Navigation bar, when one button is pushed one of the UIViews is displayed and when the other button is pushed the other UIView is displayed. I want to put a UITableView on one of the views. However, the UITableView requires the UIViewController to use the UITableViewDelegate and UITableViewDataSource. Having implemented this for my UIView (subview) containing the UTTableView, when I click on the button for the other view, which does not contain a table, I get errors and the application croaks.

我假设(可能是错误的)我的问题是我试图对两个子视图使用相同的 UIViewController,但只有一个包含表格.

I am assuming (possibly incorrectly) that my issue is that I am trying to use the same UIViewController for both subviews, but only one contains a table.

问题 1) 是否可以执行我上面描述的操作?意思是,如果我遇到问题,则说明连接不正确.

所以,我走上了创建两个独立 UIViewControllers 的道路;每个视图一个.不确定这是明智的方法.现在我只是在寻找有关执行此操作的最佳方法的建议.预先感谢您的帮助.

So, I went down a path of creating two separate UIViewControllers; one for each view. Not sure this is the smart approach. Now I am just looking for advice on the best way to do this. Thank you in advance for your help.

为了更清楚我要做什么.我希望在单击栏上的第一个按钮时将蓝色视图放在粉红色视图所在的位置,而在单击第二个按钮时将黄色视图放在粉红色视图所在的位置.本质上,粉红色视图永远不会显示,甚至可能不需要在 UtilityViewController 上.

To be more clear about what I am trying to do. I want the blue view to be put where the pink view is when the first button on the bar is clicked and I want the yellow view to be put where the pink view is when the second button is clicked. Essentially the pink view will never be displayed and may not even need to be on the UtilityViewController.

推荐答案

将每个都作为 UIViewController(或其子类)是实现您想要做的事情的方法.UITabBarController 已经这样做了:https://developer.apple.com/library/ios/documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html

Having each as a UIViewController (or a subclass thereof) is the way to go about what you are trying to do. The UITabBarController does this already: https://developer.apple.com/library/ios/documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html

这篇关于如何使用故事板将 UITableView 添加到多个子视图之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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