I am writing a test to confirm the if a method shifts the focus to next textField. I tried the code from iOS unit test: How to set/update/examine firstResponder? . But it fails.
- (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]);
}
The function completionBlockHelper
contains the code to make the txtYear
become first responder.
Any suggestions will be helpful.
The window needs to become the key window. In Swift: window.makeKeyAndVisible()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.