在 Xcode 9.0 (9A235) 上的 UI 测试中,当 UISlider
时,使用 adjust(toNormalizedSliderPosition:)
与 UISlider
交互根本不起作用嵌套在 UITableViewCell
中。
我在许多不同的场景中进行了测试:
- 未嵌入 UITableView
的普通 UISlider
可以与 adjust
方法配合使用。
- 与 UITableView
共存但不在 TableView 单元格内的 UISlider
继续与 adjust
一起使用
- UITableView
中的 UISlider
可以被唯一标识。
- UITableView
中标识的 UISlider
可以响应简单事件,例如 tap()
- UITableView
中标识的 UISlider
根本无法与 adjust
方法一起使用,即使我将行数修改为 1 也是如此。错误消息是:
Failure fetching attributes for element pid: 24415, elementOrHash.elementID: 106102876671744.43: Error Domain=XCTDaemonErrorDomain Code=13 "Fetching value for attribute 5011 returned AX error -25205." UserInfo={NSLocalizedDescription=Fetching value for attribute 5011 returned AX error -25205.}
网上找到的相关讨论: https://forums.developer.apple.com/thread/77445
我已上传my code online如果有人有兴趣的话也可以看看。
我已经提交了bug report向苹果公司询问此事。我要问的是,有谁知道当 slider 嵌套在 UITableViewCell
中时可以用来调整 UISlider
值的可能解决方法?谢谢!
最佳答案
您可以使用此作为解决方法:
func testSliderAdjustsInTableView() {
let app = XCUIApplication()
app.staticTexts["Slider in Table View UI Test"].tap()
let cell = app.tables.element.cells["cell 0"]
let button = cell.buttons["Test Button"]
button.tap()
let slider = cell.sliders["value slider"]
XCTAssert(slider.exists)
let fiftyPercent = slider.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
let ninetyPercent = slider.coordinate(withNormalizedOffset: CGVector(dx: 0.9, dy: 0.5))
fiftyPercent.press(forDuration: 0.1, thenDragTo: ninetyPercent)
XCTAssertEqual(slider.value as! String, "90 %")
}
关于ios - 用户界面测试: Slider fails to adjust when nested in Table View Cell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46785790/