I am trying to implement "previous," "next," and "done" buttons for a series of UITextFields, each of which is contained in a UITableViewCell in a grouped UITableView. I hold on to the UITextFields in an NSMutableArray, and keep an integer pointing to the UITextField that is currently active. Here are the two selectors that get fired when the Previous and Next buttons are tapped, respectively.
-(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];
}
}
As you can see, I am logging the window property of the current & next text field, and in the didSelectNextButton, everything is correct. However, in didSelectPreviousButton, nextTextField.window is always nil. Why would this be happening?
(Note that the previous button is enabled only after the user has tapped the next button once.)