I\'m a complete beginner on iOS dev and I want to create a little iOS application. On this application, 3 UIPickerViews
are supposed to display different data.
I would suggest to define a variable in controller then decide the value based on field selection
func textFieldDidBeginEditing(_ textField: UITextField) {
if(textField == self.txtAge){
**isAgeField=0**
self.pickUp(txtAge)
}else{
**isAgeField=1**
self.pickUpTimezone(timezonetxt)
}
}`
then you can add condition inside the picker view as below
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if isAgeField == 1 {
return timeZoneList.count
}else {
return arrAge.count
}
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?{
if isAgeField == 1 {
return timeZoneList[row]
}else {
return arrAge[row] as? String
}
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
**if isAgeField == 1 {**
timeZonepickerViewIndex = row
}else {
selectedIndex = row
}
}