【发布时间】:2019-05-24 01:35:16
【问题描述】:
我有一个自定义 UIView,它有一个 UITableView 作为子视图。
我已经为UIView 和UITableView 设置了accessibilityLabel 和accessibilityIdentifier。但是,我只能在我的 UITests 上查询UIView,并且表格视图根本不会出现。我还将isAccessibilityElement 设置为true。
public lazy var tableView: UITableView = {
let tableView = UITableView()
tableView.dataSource = self
tableView.delegate = self
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
return tableView
}()
// MARK: - Initialization
override init(frame: CGRect) {
super.init(frame: .zero)
commonInit()
self.layer.borderColor = UIColor.lightGray.cgColor
self.layer.borderWidth = 1
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
// MARK: - Private Methods
private func commonInit() {
isAccessibilityElement = true
accessibilityLabel = "Filter View"
tableView.isAccessibilityElement = true
tableView.accessibilityLabel = "Filter View Table"
tableView.accessibilityIdentifier = "Filter View Table"
addSubview(tableView)
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[tableView]-0-|", options: .alignAllLeft, metrics: nil, views: [ "tableView": tableView ]))
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[tableView]-0-|", options: .alignAllLeft, metrics: nil, views: [ "tableView": tableView ]))
}
我正在访问我的 UITests 中的控件,例如:
let filterView = app.otherElements["Filter View"] // Custom View
XCTAssertTrue(filterView.exists)
let filterTableView = filterView.otherElements["Filter View Table"] // Table View as Custom View's subview
XCTAssertTrue(filterTableView.exists)
【问题讨论】:
-
我不知道您的 tableView 是如何初始化的。在您通过标识符访问它之前,您的 tableView 是否已初始化?