问题描述
所以,我正在尝试创建2个选择器视图,第二个选择器视图将具有3个不同的数组选项,第一个选择器视图选项将根据选择的选项确定您将拥有的数组选项。请帮忙!我尝试了许多不同的方法,这是我当前的代码,非常感谢!
导入UIKit
StrikingOptions类:UIViewController {
@IBOutlet weak var Options: UITextField!
@IBOutlet weak var SecondOptions: UITextField!
var firstOptions = ["Offense","Defense","Movement"]
var secondOptions1: [String] = ["Jab","Cross","Uppercut"]
var secondOptions2 = ["Blocking","Parrying","Counters"]
var secondOptions3 = ["Directional Movement","Angles","Head Movement" ]
func configure2(with secondOptions: [String]) {
self.secondOptions1 = secondOptions
self.secondOptions2 = secondOptions
self.secondOptions3 = secondOptions
}
var firstOptionsPicker = UIPickerView ()
var secondOptionsPicker = UIPickerView ()
override func viewDidLoad() {
super.viewDidLoad()
Options.inputView = firstOptionsPicker
SecondOptions.inputView = secondOptionsPicker
Options.placeholder = "Select an Option"
SecondOptions.placeholder = "Select an Option"
Options.textAlignment = .center
SecondOptions.textAlignment = .center
firstOptionsPicker.delegate = self
firstOptionsPicker.dataSource = self
secondOptionsPicker.delegate = self
secondOptionsPicker.dataSource = self
firstOptionsPicker.tag = 1
secondOptionsPicker.tag = 2
}
}
扩展名StrikingOptions:UIPickerViewDataSource,UIPickerViewDelegate {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView,numberOfRowsInComponent component: Int) -> Int {
switch pickerView.tag {
case 1:
return firstOptions.count
case 2:
if firstOptions == ["Offense"] { return secondOptions1.count }
case 3: if firstOptions == ["Defence"] { return secondOptions2.count }
case 4: if firstOptions == ["Movement"] { return secondOptions3.count }
default:
return 3
}
return 3
}
func pickerView(_ pickerView: UIPickerView,titleForRow row: Int,forComponent component: Int) -> String? {
switch pickerView.tag {
case 1:
return firstOptions[row]
case 2:
return secondOptions1[row]
default:
return "Data not found"
}
}
func pickerView(_ pickerView: UIPickerView,didSelectRow row: Int,inComponent component: Int) {
switch pickerView.tag {
case 1:
Options.text = firstOptions[row]
Options.resignFirstResponder()
case 2:
SecondOptions.text = secondOptions1[row]
SecondOptions.resignFirstResponder()
SecondOptions.text = secondOptions2[row]
SecondOptions.resignFirstResponder()
SecondOptions.text = secondOptions3[row]
SecondOptions.resignFirstResponder()
if firstOptions == ["Offense"] { secondOptions1 = ["Takedowns","Top Battle","Bottom Battle","Survival"] } else if firstOptions == ["Defence"] { secondOptions2 = ["Blocking","Counters"] } else if firstOptions == ["Movement"] { secondOptions3 = ["Directional Movement","Head Movement" ] }
default:
return
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)