gpt4 book ai didi

json - 选择器 View : I want data in picker view 2 change with picker view 1 when select data from picker view 1

转载 作者:行者123 更新时间:2023-11-30 10:32:13 29 4
gpt4 key购买 nike

我对选择器 View 有一些疑问我有两个选择器 View 选择器 View 1 = getpPlandateDCPlanData选择器 View 2 = getpShipmentDCPlanData

当从选择器 View 1 中选择数据时,我希望选择器 View 2 中的数据随选择器 View 1 一起更改

var getpPlandateDCPlanData = ["20190118","20190119"]
var getpShipmentDCPlanData = ["4505023244","4505023274"]
//  Picker view function
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if pickerView == pickerview1 {
return self.getpPlandateDCPlanData.count
}
else if pickerView == pickerview2{
return self.getpShipmentDCPlanData.count
}
return 1

}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if pickerView == pickerview1{
return getpPlandateDCPlanData[row]
//return self.convertToString(dateString: getpPlandateDCPlanData[row], formatIn: "yyyyMMdd", formatOut: "MMM dd, yyyy")
}
else if pickerView == pickerview2{
return getpShipmentDCPlanData[row]
}
return nil;

}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
//if getpPlandateDCPlanData.count > 0 && getpPlandateDCPlanData.count >= row && getpShipmentDCPlanData.count >= row {
if getpPlandateDCPlanData.count >= row && getpShipmentDCPlanData.count >= row {
if pickerView == pickerview1 {
getpPlanDatePickerView.text = getpPlandateDCPlanData[row]
print("PlanDatePickerView ==> \(getpPlandateDCPlanData)")
}
else if pickerView == pickerview2 {
getpShipmentPickerView.text = getpShipmentDCPlanData[row]
print("ShipmentPickerView ==> \(getpShipmentDCPlanData)")
}//if
}//if
}

最佳答案

您在现有代码中几乎已经完成了 - 只需使用 didSelectRow 方法来检测 pickerView1 中的更改,然后在 pickerView2 中设置行>。我在下面添加了一个简单的示例,只是将 pickerView 2 中的行交换到 pickerView1 的相反行。

 func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if pickerView === pickerView1 {
switch row {
case 0: pickerView2.selectRow(1, inComponent: 0, animated: true)
case 1: pickerView2.selectRow(0, inComponent: 0, animated: true)
default: break
}
}
}

关于json - 选择器 View : I want data in picker view 2 change with picker view 1 when select data from picker view 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58911492/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com