如何使用swift显示和/或隐藏子视图 [英] How do I show and/or hide a subview using swift

查看:761
本文介绍了如何使用swift显示和/或隐藏子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在我的故事板中创建了一个ViewControl,它有3个子视图。每个表示我想要显示的不同视图,具体取决于在上一个屏幕(NavControl)上选择的表行。我首先检查通过Attributes Inspector的hidden属性隐藏的所有子视图。每个视图中的所有对象都不是隐藏的,而是被隐藏的,因为子视图本身是隐藏的(显然)。我想我可以使用tag属性我给了三个子视图中的每个子标签一个标签(0,1和2),但是无法弄清楚如何使用它(以防万一这对我来说很有用)如何做到这一点我想在这里提一下。)

So I've created a ViewControl in my storyboard that has 3 subviews. Each one represents a different view I want to show depending on which table row was selected on the previous screen (NavControl). I start with all of the subviews hidden via the Attributes Inspector's 'hidden' attribute being checked. All of the objects within each of these views are NOT hidden, but are being hidden because the subview itself is hidden (obviously). Thinking I could use the tag attribute I've given each of the three subviews a tag (0, 1 and 2), but can't figure out how to use that either (just in case this is useful as providing me with an option of how to do this I wanted to mention it here).

那么,我如何显示然后隐藏这些子视图?我不想在子视图中浏览每个对象并将其隐藏属性切换为true / false我觉得我应该能够显示/隐藏整个子视图。因此实现了相同的结果,但更加简洁。

So, how the heck do I show and then hide any of these subviews? I don't want to go through each object in a subview and toggle its hidden property to true/false I feel like I should just be able to 'show/hide' the entire subview. thus achieving the same result, but much more succinctly.

我找不到任何可以帮助我通过网络搜索或stackoverflow搜索的内容。

I can't find anything that will help me via web searches or stackoverflow searches.

我的代码非常简单。我捕获在上一个屏幕中选择的行,并将其传递给包含子视图的详细信息屏幕上的变量。我知道这是有效的,因为我在详细信息屏幕viewDidLoad函数上设置了println()。所以现在我所要做的就是进入每个条件并告诉它显示和/或隐藏哪个子视图。

My code is very simple. I capture the row that was selected in the previous screen and pass it to a variable on the details screen that contains the subviews. I know this is working because I've set up println()'s on the details screens viewDidLoad function. So now all I have to do is going into each of these conditions and tell it which subview to show and/or hide.

谢谢我感谢所有这些社区的帮助!没有它我就会迷失。

Thanks I appreciate all of this communities help! I'd be lost without it.

推荐答案

你应该创建 IBOutlet s为三个子视图中的每一个。然后,您可以直接从这些引用中显示/隐藏它们中的每一个。如果您隐藏视图,它将自动隐藏其子视图。

You should create IBOutlets for each of the three subviews. Then you can show/hide each of them directly from those references. If you hide a view, it will automatically hide its subviews.

这篇关于如何使用swift显示和/或隐藏子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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