I have an app I developed where I’m using two pickerview box’s using the tag property: one for gender and one for a list of items. Once I choose either pickerview, it somehow increments the other pickerview to an entry with an actual value and doesn’t start from the empty entry I created at [0]. I make my first selection and when I go into the 2nd list it’s already sitting on 50-55 (first entry with a value and sits at [1]. If i dont move from [1] to another and then back to [1] the label is still blank. - If i click off of pre-selected item and go back to it, all works fine. Pasting the pickerview code below - let me know if more info is needed and thanks in advance!
Added a video as to exactly what is happening:
https://www.youtube.com/watch?v=JnHii-c1E3M&feature=youtu.be
let gendOption = ["", "Male","Female"] //first array for first textfield
let actOption = ["", "50%-55%", "55%-60%", "60%-65%", "65%-70%", "70%-75%", "75%-80%", "80%-85%", "85%-90%", "90%-95%"] //array for 2nd textfield
let pickerView = UIPickerView()
var currentTxtFldTag : Int = 10
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
//return priorityTypes.count
if currentTxtFldTag == 10
{
return gendOption.count
}
else
{
return actOption.count
}
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
//return priorityTypes[row]
if currentTxtFldTag == 10
{
return gendOption[row]
}
else
{
return actOption[row]
}
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
//selectedPriority = priorityTypes[row]
//activityTextBox.text = selectedPriority
if currentTxtFldTag == 10
{
genderSelection.text = gendOption[row]
}
else
{
activityTextBox.text = actOption[row]
}
}
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
if textField.tag == 10 // *** OPTION
{
currentTxtFldTag = 10
}
else // activity OPTION
{
currentTxtFldTag = 20
}
pickerView.reloadAllComponents()
return true
}
func createPickerView() {
let pickerView = UIPickerView()
pickerView.delegate = self
activityTextBox.inputView = pickerView
}