Note that there are some explanatory texts on larger screens.

plurals
  1. POtextFieldShouldBeginEditing + UIKeyboardWillShowNotification + OS 3.2
    primarykey
    data
    text
    <p>I have multiple textfields on a UIView.</p> <p>I resign for a previous textField in textFieldShouldBeginEditing method, where following sequence of events are performed</p> <ul> <li><p>UIKeyboardWillHideNotification is received corresponding to that field where the keyboard for the previous field is hidden. </p></li> <li><p>the method textFieldShouldBeginEditing returns a YES and then</p></li> <li><p>UIKeyboardWillShowNotification is received where the keyboard for the current field is displayed.</p></li> </ul> <p>However, in OS 3.2 even though textFieldShouldBeginEditing returns a YES, UIKeyboardWillShowNotification for the current field is not received.</p> <p>The logic works for OS &lt; 3.2</p> <p>Any ideas where I might be doing wrong?</p> <p>Listed below a part of my code (with only two text fields in xib).</p> <p>I need to perform a set of operations at keyboardWillShow and keyboardWillHide Look at the difference on running the code in OS 3.2 and OS &lt; 3.2</p> <p>Can anyone explain the difference in behaviour?</p> <h2>.h</h2> <pre><code>@interface ExampleViewController : UIViewController { IBOutlet UITextField *numericTextField; IBOutlet UITextField *alphaTextField; UITextField *lastTextField; int lastCursorPos; int cursorPosition; NSMutableArray *textFields; } @property (nonatomic, retain) UITextField *lastTextField; @property (nonatomic, retain) NSMutableArray *textFields; @end </code></pre> <h2>.m</h2> <pre><code>- (void)viewWillAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:self.view.window]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:self.view.window]; self.view.backgroundColor = [UIColor groupTableViewBackgroundColor]; self.textFields = [[NSMutableArray alloc] initWithCapacity:2]; [self.textFields insertObject:alphaTextField atIndex:0]; [self.textFields insertObject:numericTextField atIndex:1]; cursorPosition = 1; [numericTextField becomeFirstResponder]; } -(void)viewWillDisappear:(BOOL)animated { [self setEditing:NO animated:YES]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { int index; for(UITextField *aField in self.textFields){ if (textField == aField){ index = [self.textFields indexOfObject:aField]; } } if(index&gt;=0 ){ lastCursorPos = cursorPosition; self.lastTextField = [self.textFields objectAtIndex:lastCursorPos-1]; cursorPosition = index +1; } [self.lastTextField resignFirstResponder]; return YES; } - (BOOL)textFieldShouldEndEditing:(UITextField *)textField { return YES; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } - (void)keyboardWillShow:(NSNotification *)notif { NSLog(@"Inside keyboardWillShow"); } - (void)keyboardWillHide:(NSNotification *)notif { NSLog(@"Inside keyboardWillHide"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload