根据文本字段中的数据重新加载pickerview

时间:2018-03-16 13:35:52

标签: ios swift uipickerviewcontroller

我正在使用Swift 3.
这是代码:

public func numberOfComponents(in pickerView: UIPickerView) -> Int {
    return 1
}

public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {

    if (selectedstatename == nil) {
        return dataList.count
    } else {
       return dataList1.count
    }
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {

    if (selectedstatename == nil) {
        return dataList[row].title
    } else {
        return dataList1[row].dist
    }
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

    if (selectedstatename == nil) {
        cityField.text = dataList[row].title
        selectedstatename = cityField.text
        self.pickerView.reloadAllComponents()
        cityField.resignFirstResponder()
    } else {
        self.pickerView.reloadAllComponents()
        cat.text = dataList1[row].dist
        cat.resignFirstResponder()
    }
}

0 个答案:

没有答案