Quantcast
Channel: Active questions tagged uipickerview - Stack Overflow
Viewing all articles
Browse latest Browse all 592

xcode11 how to give a selected option an action, in a PickerView. So that when I select an option in the selected array, I can perform an action to it

$
0
0

For example I select in the PickerView ( country: Scotland, City: Aberdeen ) once I have selected both options in a picker view, I would select a button and have that action take me to another page with information about Scotland, Aberdeen specifically.

What I am trying to do is have my PickerView options take me to another page contained with data specific with those options selected. This is what I have coded so far.

import UIKitclass GrapplingViewController: UIViewController {    @IBOutlet weak var trainingTextField: UITextField!    @IBOutlet weak var areaTextField: UITextField!    @IBOutlet weak var focusTextField: UITextField!    let training = ["Skill Reciting", "Sparring"]            let area = ["Takedowns", "Top Battle", "Bottom Battle", "Survival"]            let focus = ["Full Training", "Specific Training"]            var trainingPickerView = UIPickerView ()            var areaPickerView = UIPickerView ()            var focusPickerView = UIPickerView()   override func viewDidLoad() {          super.viewDidLoad()          title = "Grappling"                trainingTextField.inputView = trainingPickerView                areaTextField.inputView = areaPickerView                focusTextField.inputView = focusPickerView                trainingTextField.placeholder = "Select training type"                areaTextField.placeholder = "Select start position"                focusTextField.placeholder = "Select your focus"                trainingTextField.textAlignment = .center                areaTextField.textAlignment = .center                focusTextField.textAlignment = .center                trainingPickerView.delegate = self                trainingPickerView.dataSource = self            areaPickerView.delegate = self            areaPickerView.dataSource = self                focusPickerView.delegate = self            focusPickerView.dataSource = self                trainingPickerView.tag = 1                areaPickerView.tag = 2                focusPickerView.tag = 3    }            }        extension GrapplingViewController: UIPickerViewDataSource, UIPickerViewDelegate {            func numberOfComponents(in pickerView: UIPickerView) -> Int {                return 1            }            func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {                switch pickerView.tag {                case 1:                    return training.count                    case 2:                        return area.count                case 3:                    return focus.count                default:                    return 1                }            }            func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {                switch pickerView.tag {                case 1:                    return training[row]                case 2:                        return area[row]                case 3:                    return focus[row]                default:                    return "Data not found"            }            }            func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {                switch pickerView.tag {                    case 1:                        trainingTextField.text = training[row]                        trainingTextField.resignFirstResponder()                    case 2:                           areaTextField.text = area[row]                            areaTextField.resignFirstResponder()                    case 3:                        focusTextField.text = focus[row]                        focusTextField.resignFirstResponder()                    default:                        return                }            }         @IBAction func startButton(_ sender: UIButton) {}}

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>