从第二个pickerView中选择最后一个数组值时,Multi pickerView会崩溃吗?

时间:2017-06-18 03:34:01

标签: ios swift3 xcode8

一切正常,直到我选择第二个UIpickerView中的最后一项。 有小费吗?如果有缺少结尾括号只是添加一些我怀疑我留下任何,这里是代码。 Ps:对不起,如果看起来有点马虎

    class RegisterViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {


    @IBOutlet weak var Country: UILabel!

    @IBOutlet weak var pickerView1: UIPickerView! //this is pickerView for Country


    @IBOutlet weak var Ethnicity: UILabel!   //this is pickerView for Ethnicity

    @IBOutlet weak var pickerView2: UIPickerView!

   //country constant
    let country = ["United States", "China", "Japan", "Germany", "France", "United Kingdom", "Italy", "Brazil", "Canada", "Spain", "Australia", "Sweden", "Mexico", "Russia", "Turkey", "New Zealand", "Ireland", "India", "Jamica", "Puerto Rico", "Hong Kong", "Russia"]

    //ethnicity constant
    let ethnicity = ["Black", "Causion", "Pacific Islander", "Indian", "Native American", "Middle Eastern", "Asian", "Russian", "Hispanic", "Irish", "German", "Jewish", "Mixed Race", "Other"]

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
    if pickerView1 == pickerView1 {
        return 1
    } else if pickerView2 == pickerView2 {
        return 1
    }
    return 1

    }

    func pickerView(_ _pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    if (pickerView1 == pickerView1){
        return country.count
    }else if (pickerView2 == pickerView2){
        return ethnicity.count
    }
    return 1

    }

这看起来像问题区号。 Xcode调试带我到这里

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int,     forComponent component: Int) -> String? {
    if (pickerView == pickerView1){
        return country[row]
    }else if (pickerView == pickerView2){
        return ethnicity[row]
    }
    return ("")
    }

//view did load 
    override func viewDidLoad() {
    super.viewDidLoad()
    self.pickerView1.isHidden = false
    self.pickerView2.isHidden = false
   }

0 个答案:

没有答案