在 UI 测试中,我可以使用以下代码获取第一个单元格:
let app = XCUIApplication()
app.launch()
let tablesQuery = app.tables
let cell = tablesQuery.children(matching:.any).element(boundBy: 0)
如何检查该单元格是否包含 imageview ?
在 UI 测试中,我可以使用以下代码获取第一个单元格:
let app = XCUIApplication()
app.launch()
let tablesQuery = app.tables
let cell = tablesQuery.children(matching:.any).element(boundBy: 0)
如何检查该单元格是否包含 imageview ?
public func hasImageViewInside(_ cell: UITableViewCell) -> Bool {
for child in cell.subviews {
if let _ = child as? UIImageView {
return true
}
}
return false
}
for viw in cell.contentView.subviews {
if ((viw as? UIImageView) != nil) {
print("123")
}
}
for case let imageView as UIImageView in cell.contentView.subviews {
if imageView.tag == 1001 {
imageView.image = UIImage(named: "myCustomImage")
}
}
//OR Altervnatively
cell.contentView.subviews.flatMap { $0 as? UIImageView }.forEach { imageView in
if imageView.tag == 1001 {
imageView.image = UIImage(named: "myCustomImage")
}
}