问题
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
}
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?
回答1:
To hide or show buttons, you use isHidden
property. To hide buttons:
button1.isHidden = true
button2.isHidden = true
To show buttons
button1.isHidden = false
button2.isHidden = false
Also the code after return doesn't get executed, you know that right?
来源:https://stackoverflow.com/questions/49913442/swift-4-show-hide-button-based-on-picker-view-selection