У меня есть два компонента в UIPickerView.Один для страны, а другой для города.Я хочу, чтобы при нажатии кнопки «Страна» отображался только один компонент, а при нажатии кнопки «Город» - другой.
@IBOutlet weak var myPicker: UIPickerView!
var pickerData = [["India", "Pakistan", "Bangladesh", "USA", "Afganistan", "Russia", "Nepal", "Bhutan"], ["Chandigarh", "Punjab", "Ludhiana", "Amritsar", "Shimal", "Una"]]
override func viewDidLoad() {
super.viewDidLoad()
myPicker.isHidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return pickerData.count
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerData[component].count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerData[component][row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
// print(pickerData[row])
showCountry.text = pickerData[component][row]
}
@IBAction func showCountry(_ sender: Any) {
myPicker.isHidden = false
}
На данный момент, когда я нажимаю на страну, отображаются оба компонента, но я просто хочупоказать один компонент в окне выбора.