Swift 4 show/hide button based on picker view selection

假装没事ソ 提交于 2019-12-13 03:42:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!