gpt4 book ai didi

ios - 在双组件 pickerView 中查找两个变量

转载 作者:行者123 更新时间:2023-11-30 12:19:05 26 4
gpt4 key购买 nike

我找不到任何地方解释如何从 pickerView 的两个组件获取信息。现在它所做的就是将最后移动的组件中的字符串放入测试标签中。我真的不需要它们出现在销售点,而只是需要它们。我还想使用我注释掉的数组格式。

@IBOutlet weak var itemPickerView: UIPickerView!

var pickerViewArray = [["Items", "Key", "Rock"], ["Action", "Turn", "Hit"]]

func numberOfComponents(in pickerView: UIPickerView) -> Int {
return pickerViewArray.count
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerViewArray[component].count
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerViewArray[component][row]
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
itemSelected = pickerViewArray[component][row]
pickerOutletTest.text = itemSelected
}

@IBOutlet weak var pickerOutletTest: UILabel!

最佳答案

使用以下方法更改 didSelectRow 方法。

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
pickerOutletTest.text = pickerViewArray[0][pickerView.selectedRow(inComponent: 0)] + " " + pickerViewArray[1][pickerView.selectedRow(inComponent: 1)]
}

关于ios - 在双组件 pickerView 中查找两个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45027274/

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