Two UIPickerViews and different combinations lead to different photos

I am very new to swift Xcode and would like some help on UIPickerView.

I am trying to create two UIPickerViews, one called “From” and one called “To”. “From” contains A, B and “To” contains B, C

  • Bring App to foreground
  • Get CellID, MCC, MNC, LAC, and Network in iOS 5.1
  • How can I create a big, red UIButton with the iPhone SDK?
  • Handling Game Center authentication
  • AVPlayerLayer Position in UIView Layer
  • Bundle.main.path(forResource:ofType:inDirectory:) returns nil
  • Basically, if “From” is A and “To” is B then a Photo of car will appear on the same viewController.
    if “From” is B and “To” is B then a photo of strawberry will appear and so on.

    Can anyone give me any hints on how to do this? I’ve only managed to create the first UIPickerView.

    import UIKit
    
    class ViewController: UIViewController,UIPickerViewDelegate, UIPickerViewDataSource {
    
        @IBOutlet var Picker1:UIPickerView!
    
        var Array = ["A","B","C"]
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib
    
            Picker1.delegate = self
            Picker1.dataSource = self
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
        func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
            return Array[row]
        }
    
        func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
            return Array.count
        }
    
        func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {   
            return 1
        }
    }
    

    2 Solutions Collect From Internet About “Two UIPickerViews and different combinations lead to different photos”

    var savedVal1 = "" as String
    var savedVal2 = "" as String
    var array1 = NSArray()
    var array2 = NSArray()
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        Picker1.delegate = self
        Picker1.dataSource = self
        Picker1.tag = 1
    
        Picker2.delegate = self
        Picker2.dataSource = self
        Picker2.tag = 2
    }
    
    
    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        if pickerView.tag == 1 {
            return array1[row]
        }
        else{
           return array2[row]
        }
    }
    
    
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        if pickerView.tag == 1 {
           return array1.count
        }
        else{
           return array2.count
        }
    }
    
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int{
    
        return 1
    }
    
    func pickerView(pickerView: UIPickerView!, didSelectRow row: Int, inComponent component: Int){
            if pickerView.tag == 1 {
                savedVal1 = array1[row]
                // compare 2 values here & then take steps which fulfill your criteria.
    
            }
            else{
                savedVal2 = array2[row]
                //compare 2 values here & then take steps which fulfill your criteria.
            }
        }
    

    Hope it helps.

    Where is your PickerView2?

    @IBOutlet var Picker2:UIPickerView!
    

    In viewdidload load as you done

    Picker1.delegate = self
    Picker1.dataSource = self
    

    If you are using same data source or different please check the picker view in UIPickerViewDelegate, UIPickerViewDataSource method like

     If (Picker1) {
    
    } else if (Picker2) {
    
    }