1

UIPickerView最初のコンポーネントに基づく2 番目のコンポーネントをリロードできません。を使用してみましたreloadAllComponentsが、動作しないかクラッシュします。私が取り組もうとしているのは、車のメーカーを左側に、車のモデルを右側に配置することです。そのため、車が変更されると、同時に適切なコンポーネント モデルも変更されます。

class RegistrationPage: UIViewController,UIPickerViewDataSource, UIPickerViewDelegate {
    @IBOutlet weak var usernameTextField: UITextField!
    @IBOutlet weak var passwordTextField: UITextField!
    @IBOutlet weak var passwordReTypeTextField: UITextField!
    @IBOutlet weak var makePicker: UIPickerView!
    @IBOutlet weak var modelPicker: UIPickerView!
    @IBOutlet weak var licenseTagTextField: UITextField!
    var picker1Options = []
    var picker2Options = []

    @IBAction func SubmitButton(sender: AnyObject) {

    }

    override func viewDidLoad() {
        super.viewDidLoad()

        makePicker = UIPickerView()
        modelPicker = UIPickerView()
        let makeAndModel = CarMakeModel();

        picker1Options = makeAndModel.makeValues()
        let firstValue = picker1Options.objectAtIndex(0)
        picker2Options = makeAndModel.modelValues(firstValue as! String)

    }

    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        return 2
    }

    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        if (component == 0) {
            return picker1Options.count
        } else {
            return picker2Options.count
        }

    }

    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
        if component == 0 {
            return "\(picker1Options[row])"
        } else {
            let makeAndModel = CarMakeModel();
            let currentValue = picker1Options.objectAtIndex(row)
            var picker2ptions = makeAndModel.modelValues(currentValue as! String)
            return "\(picker2ptions[row])"
        }
    }
    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        let makeAndModel = CarMakeModel();
        let currentValue = picker1Options.objectAtIndex(row)
        var picker2ptions = makeAndModel.modelValues(currentValue as! String)
        pickerView.reloadAllComponents()

    }
}

ありがとう!

4

2 に答える 2