title: Why is resignFirstResponder being called twice in iOS 5.0 but only once in iOS4.2-4.3?
body: <p>I have a app in the App Store compiled for 4.2 that is acting odd when running under iOS 5.0.  I have tracked it down to <code>resignFirstResponder</code> being called twice under iOS 5.0 while it was only being called once under iOS 4.2 &amp; 4.3.</p>
  
  <p>I have a derived a class from <code>UITextField</code> where I override <code>resignFirstResponder</code>.  See the sample code below.</p>
  
  <p>Under iOS 4.2 &amp; 4.3 I see the following in the console:</p>
  
  <pre><code>textFieldShouldReturn
  resignFirstResponder
  textFieldDidEndEditing
  </code></pre>
  
  <p>Under iOS 5.0 I see the following in the console:</p>
  
  <pre><code>textFieldShouldReturn
  resignFirstResponder
  resignFirstResponder
  textFieldDidEndEditing
  </code></pre>
  
  <p>Running the code on the device and simulator are giving constant results. Am I missing something or is this a bug?</p>
  
  <h2>The iOS 5.0 stack trace</h2>
  
  <pre><code>#0  -[BugTextField resignFirstResponder] (self=0x681b530, _cmd=0x3769b41) at /Users/.../BugTextField.m:14
  #1  0x006c05a6 in -[UIFieldEditor resignFirstResponder] ()
  #2  0x006374e3 in -[UIView(Hierarchy) _willMoveToWindow:] ()
  #3  0x006362c2 in __UIViewWillBeRemovedFromSuperview ()
  #4  0x006360d7 in -[UIView(Hierarchy) removeFromSuperview] ()
  #5  0x006bfff7 in -[UIFieldEditor becomeFieldEditorForView:] ()
  #6  0x006ae37b in -[UITextField _resignFirstResponder] ()
  #7  0x006eb8d4 in -[UIResponder _finishResignFirstResponder] ()
  #8  0x006eba20 in -[UIResponder resignFirstResponder] ()
  #9  0x006ae249 in -[UITextField resignFirstResponder] ()
  #10 0x00017f68 in -[BugTextField resignFirstResponder] (self=0x681b530, _cmd=0x3769b41) at /Users/.../BugTextField.m:16
  #11 0x0001828f in -[BugTextFieldVC textFieldShouldReturn:] (self=0x6829750, _cmd=0x18c5b, textField=0x681b530) at /Users/.../BugTextFieldVC.m:40
  </code></pre>
  
  <h2>BugTextField.h</h2>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface BugTextField : UITextField
  
  @end
  </code></pre>
  
  <h2>BugTextField.m</h2>
  
  <pre><code>#import "BugTextField.h"
  
  @implementation BugTextField
  
  - (BOOL) resignFirstResponder
  {
      NSLog(@"resignFirstResponder");
  
      return [super resignFirstResponder];
  }
  
  @end
  </code></pre>
  
  <h2>BugTextFieldVC.h</h2>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  @class BugTextField;
  
  @interface BugTextFieldVC : UIViewController &lt;UITextFieldDelegate&gt; {
      BugTextField *bugTextField;
  }
  
  @end
  </code></pre>
  
  <h2>BugTextFieldVC.m</h2>
  
  <pre><code>#import "BugTextFieldVC.h"
  #import "BugTextField.h"
  
  @implementation BugTextFieldVC
  
  - (id) init
  {
      if ( !(self = [super init]) )
      {
          return self;
      }
  
      // One text field with 100 height keyboard
      bugTextField = [[BugTextField alloc] initWithFrame:CGRectMake(10, 10, 300, 30)];
      bugTextField.borderStyle = UITextBorderStyleRoundedRect;
      bugTextField.delegate = self;
      [self.view addSubview:bugTextField];
  
      return self;
  }
  
  - (void) dealloc
  {
      [bugTextField release];
  
      [super dealloc];
  }
  
  - (BOOL) textFieldShouldReturn:(UITextField *)textField
  {
      NSLog(@"textFieldShouldReturn");
  
      [textField resignFirstResponder];
  
      return YES;
  }
  
  - (void) textFieldDidEndEditing:(UITextField *)textField
  {
      NSLog(@"textFieldDidEndEditing");
  }
  
  @end
  </code></pre>