条件下的二进制运算符错误

时间:2018-02-22 11:11:30

标签: ios swift3 uipickerview

我想在pickerview行上给出条件,但它只是给我错误。 二进制运算符不能应用于操作数

let viewList: [String] = ["Fixed", "Recurring"]

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

    if (viewList[row] == 0) {

    }
}

1 个答案:

答案 0 :(得分:0)

更新回答

尝试这样做:

class MyViewController: UIViewController {
    fileprivate let viewList: [String] = ["Fixed", "Recurring"]
}

// MARK: - UIPickerViewDelegate
extension MyViewController: UIPickerViewDelegate {
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
            print("Selected value \(viewList[row]) at row \(row)")

            if viewList[row] == "Fixed" {
                print("Fixed has been selected!")
            }
    }
}

问题来自您的情况,请尝试下面的代码。

更多信息:Apple Documentation - Collection Types