在單元測試中,我試圖在UITextField上調用becomeFirstResponder方法,但是我得到NO,即它不成爲第一響應者。Make UITextField first responder
代碼看起來如下:
UITextField *textField = [self.controller.searchBar valueForKey: @"_searchField"];
// textField = [[UITextField alloc] initWithFrame:CGRectMake(10.0, 10.0, 400.0, 44.0)];
[self.navigationController.navigationBar addSubview:textField];
textField.enabled = YES;
STAssertTrue([textField becomeFirstResponder],
@"TextField should be a first responder.");
我在這裏失去了一些東西?
根據對象生命週期的時刻,你正在調用這個調用,'self.navigationCopntroller.navigationBar'可能== nil。如果是這樣,否則是正確的行爲。 –