我试图在选择器视图中返回所选项目的索引,但我没有成功。单击按钮时,我需要传输元素的索引,然后根据索引调用特定的函数。
@IBAction func myButton(_ sender: UIButton) {
let row = [pickerView.selectedRow(inComponent: 0)]
}
我尝试将行的值打印到控制台中,但事实证明,但是当我尝试创建条件时,如果row = 0等等,我得到一个错误。请帮帮我!
答案 0 :(得分:0)
var row: Int = 0
var repeatPickerData = [Any]()
var repeatPickerView: UIPickerView?
if let aComponent = repeatPickerView?.selectedRow(inComponent: 0) {
row = aComponent
}
strPrintRepeat = repeatPickerData[row]