我正在编写一个测试来确认方法是否将焦点转移到下一个textField。我尝试了iOS unit test: How to set/update/examine firstResponder?的代码。但它失败了。
- (void)testFocusMovedToYearField {
UIWindow *window = [[UIWindow alloc] init];
[window addSubview:self.dateCell.txtDay];
[window addSubview:self.dateCell.txtYear];
[self.dateCell completionBlockHelper];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:5.0]];
XCTAssertTrue([self.kioskDateCell.txtYear isFirstResponder]);
}
函数completionBlockHelper
包含使txtYear
成为第一响应者的代码。
任何建议都会有所帮助。
答案 0 :(得分:1)
窗口需要成为关键窗口。在Swift中:window.makeKeyAndVisible()