Why does UITextField start editing when the view controller is popped off the navigation stack?

I have a single UINavigationController with an arbitrary root view controller. Then I push the following subclassed UITableViewController onto the navigator 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 single line UITableViewController that contains a single UITextField.

Repro Steps:

  • Click the text box
    • "edit started" is logged as expected
  • Click "<Back" in the navigation bar
    • "complete edit" is logged as expected
    • "editing started" and "editing finished" are registered again ( unexpectedly !)

I'm trying to figure out why a textbox starts and then edits end again during a reverse animation.

Note that I can prevent this behavior by overriding viewWillDisappear:animated:

and calling resignFirstResponder

in the textbox, but I still don't understand the underlying problem.

+3


source to share





All Articles