未调用UIPickerView accessiblityLabelForComponent

时间:2019-02-07 11:34:02

标签: ios swift uikit uipickerview

我正在尝试为UIPickerView组件设置可访问性标签,但是从未调用委托方法。而且,UIInspector显示无法访问pickerView,但实际上已设置了标签。

将触发dataSource / delegate方法。只有UIAccessibilityDelegate不是。

在xcode 10.1 iOS 12.1模拟器上测试

class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate, UIPickerViewAccessibilityDelegate {

    @IBOutlet weak var pickerView: UIPickerView!

    override func viewDidLoad() {
        super.viewDidLoad()
        pickerView.isAccessibilityElement = true
        pickerView.accessibilityLabel = "TESTAccLabel"
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return 5
    }

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 2
    }

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

    func pickerView(_ pickerView: UIPickerView, accessibilityLabelForComponent component: Int) -> String? {
        return "TODO:JS"
    }
}

0 个答案:

没有答案