Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在不同UITableViewCell中级联UIPickerView_Ios_Swift_Xcode_Uitableview_Uipickerview - Fatal编程技术网

Ios 在不同UITableViewCell中级联UIPickerView

Ios 在不同UITableViewCell中级联UIPickerView,ios,swift,xcode,uitableview,uipickerview,Ios,Swift,Xcode,Uitableview,Uipickerview,我有两个不同的UIPickerView,它们位于不同的自定义UITableViewCell中。第一个UIPickerView加载页面上加载的数据。第二个pickerView是在第一个pickerView进行一些选择之后加载的。如何将第一个选定值传递给第二个pickerView?我无法使用celldidSelect,因为交互已被PickerView拾取,因此不会触发表视图委托 到目前为止,我的代码是: extension ReservationViewController: UITableView

我有两个不同的
UIPickerView
,它们位于不同的自定义
UITableViewCell
中。第一个
UIPickerView
加载页面上加载的数据。第二个
pickerView
是在第一个
pickerView
进行一些选择之后加载的。如何将第一个选定值传递给第二个
pickerView
?我无法使用cell
didSelect
,因为交互已被
PickerView
拾取,因此不会触发表视图
委托

到目前为止,我的代码是:

extension ReservationViewController: UITableViewDelegate {

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if indexPath.row == ReservationCell.MakeReservation.rawValue {
            //print value --> this is not firing
        }
    }

    func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        if indexPath.row == ReservationCell.MakeReservation.rawValue {
        //print value --> this not firing
        }
    }
}

extension ReservationLocationTableViewCell: UIPickerViewDataSource, UIPickerViewDelegate {
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }
    //Set number of rows in components

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

        return self.data.count

    }
    //Set title for each row
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {

        return data[row]


    }
    // Update textfield text when row is selected
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

        print(data[row]) // I want to pass this value to next cell that contains another PickerView

    }
}

如何将数据值传递到下一个单元格

首先将所选数据
data[row]
row
保存在
ReservationViewController
中的某个位置。然后,您可以重新加载
tableView
,为第二个
UIPickerView
执行逻辑

var selectedRow: Int = 0

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

    print(data[row]) // I want to pass this value to next cell that contains another PickerView

    // save the row
    selectedRow = row
    // do your logic in tableView's cellForRowAtIndexPath
    tableView.reloadData()
}

如何在TabeViewCell中显示选定的pickerview值