textFieldShouldBeginEditing + UIKeyboardWillShowNotification + OS 3.2

J'ai plusieurs objets textfield sur une UIView.

Je démissionne pour un textField dans textFieldShouldBeginEditing méthode, où la séquence suivante d'événements sont effectuées

  • UIKeyboardWillHideNotification est reçu correspondant au champ où le clavier pour le champ précédent est caché.
  • la méthode textFieldShouldBeginEditing retourne un OUI et puis
  • UIKeyboardWillShowNotification est reçu, dans lequel le clavier pour le champ actuel est affiché.

Cependant, dans l'OS 3.2, même si textFieldShouldBeginEditing retourne un OUI, UIKeyboardWillShowNotification pour le champ actuel n'est pas reçu.

La logique fonctionne pour les OS < 3.2

Des idées où je pourrais faire de mal?

Énumérés ci-dessous une partie de mon code (avec seulement deux champs de texte dans xib).

J'ai besoin d'effectuer un ensemble d'opérations à keyboardWillShow et keyboardWillHide Regardez la différence sur l'exécution du code dans l'OS 3.2 et OS < 3.2

Quelqu'un peut-il expliquer la différence de comportement?

.h

@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

.m

- (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>=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");
}

source d'informationauteur random