I have a UIPickerView
that selects from an array of states and the last item in the array is “outside the US”. When the last item in the array is selected I want to show another input option for country.
Currently I have the country input set to hidden in viewDidLoad
.
This is my attempt at trying to get this to work, but it keeps causing a crash on selection of the last item.
var stateOptionsList = ["", "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District Of Columbia", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming", "Outside The United States"]
let outsideOfUS = stateOptionsList[statePicker.selectedRow(inComponent: 52)] as String
print(outsideOfUS)
if selectStateInput.text == outsideOfUS {
countryContainer.isHidden = false
} else {
countryContainer.isHidden = true
}
I put the let outsideOfUs
var in the pickerView didSelectRow
. Not sure if this is where I am supposed to put this.