问题描述
所以,我正在制作一个应用程序,在让用户从选择器视图中选择他们的教育水平之后,如果他们选择大学教育,应该会出现一些按钮,上面写着副学士学位"、学士学位"和硕士'.我知道我需要做一个这样的 if 语句:
So, I'm making an app that after having the user select their level of education from a picker view and if they select college education a number of buttons are supposed to appear saying 'associates degree' 'bachelor's degree' and 'master's degree'. I know I need to make an if statement like this:
func pickerView(pickerView: UIPickerView, row: Int, forComponent component: Int) -> String! {
if educationLabel.text == educationLevel {
return education[row]
If row = "College Graduate"
//Hidden buttons code
Else
//Hidden buttons
}
但我不确定如何编写隐藏所有三个按钮的代码,因为我遇到的每个示例都只有一个按钮.我假设它类似于这里建议的内容:how to在 swift 中隐藏/显示一个按钮,并添加了按钮 2 和 3,但我使用的是 Swift 4,并且不确定我可以使用多少答案,因为它使用的是 Swift 3.有人可以帮我吗?
but I'm unsure of how to write the code that keeps all three buttons hidden as every example I've come across only had one button. I'm assuming it would be similar to what is suggested here: how to hide/show a button in swift with buttons two and three added on but I am using Swift 4 and am unsure how much of the answer I can use since it uses Swift 3. Can someone please help me out?
推荐答案
要隐藏或显示按钮,您可以使用 isHidden
属性.隐藏按钮:
To hide or show buttons, you use isHidden
property. To hide buttons:
button1.isHidden = true
button2.isHidden = true
显示按钮
button1.isHidden = false
button2.isHidden = false
返回后的代码也不会被执行,你知道吗?
Also the code after return doesn't get executed, you know that right?
这篇关于基于选择器视图选择的 Swift 4 显示/隐藏按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!