根据选择器选择 IOS、swift 确定 Segue

Determine Segue Based on picker selection IOS, swift

我目前有一个有两个选项的选择器,我正在寻找的是,根据在选择器中所做的选择,确定下面的下一个 viewController 是我尝试使用的,但是,我立即收到一条错误消息,指出最后的 "if" 语句应转换为 let 语句。下面是我的选择器的代码,并试图引导到相关的 segue。

import UIKit
import Firebase
import CoreData
import CoreLocation

class SchoolPickerViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
    @IBOutlet weak var SchoolPicker: UIPickerView!
    let pickerData = ["Ohio State University", "University of Rochester"]
    override func viewDidLoad() {
        super.viewDidLoad()
        SchoolPicker.dataSource = self
        SchoolPicker.delegate = self
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
    return 1
    }
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return pickerData.count
    }

    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return pickerData[row]
    }

    @IBAction func schoolSelectorGoButton(sender: AnyObject) {
        if pickerData = "Ohio State University" {
            performSegueWithIdentifier("ohioStateSelected", sender: sender)
        }
       if pickerData = "University of Rochester" {
           performSegueWithIdentifier("rochesterSelected", sender: sender)
        }
    }


}

你应该从数组中获取选定的选择器数据

定义

var selectedIndex = 0

然后在这一行

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? 
{
    selectedIndex = row
    return pickerData[row]
}

并在此操作中

@IBAction func schoolSelectorGoButton(sender: AnyObject) {
    if pickerData[selectedIndex] == "Ohio State University" {
        performSegueWithIdentifier("ohioStateSelected", sender: sender)
    }
}