UITextField一連のsに「前へ」、「次へ」、「完了」ボタンを実装しようとしています。これらのボタンはそれぞれUITableViewCell、グループ化されたのに含まれていUITableViewます。を保持し、現在アクティブなを指す整数を保持UITextFieldsします。[前へ]ボタンと[次へ]ボタンをそれぞれタップすると起動する2つのセレクターを次に示します。NSMutableArrayUITextField
-(IBAction)didSelectPreviousButton:(id)sender
{
if ((textFieldIndex - 1) >= 0) {
UITextField *currentField = [self.testTextFields objectAtIndex:(textFieldIndex)];
UITextField *nextTextField = [self.testTextFields objectAtIndex:(--textFieldIndex)];
BOOL result = [nextTextField becomeFirstResponder];
NSLog([NSString stringWithFormat:@"currentField's window: %@", currentField.window]);
NSLog([NSString stringWithFormat:@"nextTextField's window: %@", nextTextField.window]);
} else {
[self dismissKeyboard:sender];
}
}
-(IBAction)didSelectNextButton:(id)sender
{
if ((textFieldIndex + 1) < [self.inspectionItemSpec.numberOfTests intValue]) {
UITextField *currentField = [self.testTextFields objectAtIndex:(textFieldIndex)];
UITextField *nextTextField = [self.testTextFields objectAtIndex:(++textFieldIndex)];
BOOL result = [nextTextField becomeFirstResponder];
NSLog([NSString stringWithFormat:@"currentField's window: %@", currentField.window]);
NSLog([NSString stringWithFormat:@"nextTextField's window: %@", nextTextField.window]);
} else {
[self dismissKeyboard:sender];
}
}
ご覧のとおり、現在および次のテキストフィールドのウィンドウプロパティをログに記録していdidSelectNextButtonます。で、すべてが正しいです。ただし、ではdidSelectPreviousButton、nextTextField.windowは常にnilです。なぜこれが起こっているのでしょうか?
(前のボタンは、ユーザーが次のボタンを1回タップした後にのみ有効になることに注意してください。)