I have a single UINavigationController, with an arbitrary root view controller. Then, I push the following subclassed UITableViewController onto the nav stack:
@interface BugViewController : UITableViewController <UITextFieldDelegate>
@end
@implementation BugViewController
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] init];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 0, 200, 30)];
[textField setBackgroundColor:[UIColor yellowColor]];
[textField setDelegate:self];
[[cell contentView] addSubview:textField];
return cell;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(@"did begin editing");
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSLog(@"did end editing");
}
@end
Basically, it's just a stock UITableViewController with a single row, which contains a single UITextField.
Repro steps:
- Tap the text field
- "did begin editing" is logged, as expected
- Tap "< Back" in the nav bar
- "did end editing" is logged, as expected
- "did begin editing" and "did end editing" are logged again (unexpected!)
I am struggling to understand why the text field begins then ends editing again during the back animation.
Note that I can prevent this behavior by overriding viewWillDisappear:animated:
and calling resignFirstResponder
on the text field, but I still don't understand the underlying issue.