textFieldShouldBeginEditing + UIKeyboardWillShowNotification + ОС 3.2

У меня есть несколько текстовых полей на UIView.

Я ухожу в отставку для предыдущего текстового поля в textFieldShouldBeginEditing методе, где следование за последовательностью событий выполняется

  • UIKeyboardWillHideNotification получен, соответствуя тому полю, где клавиатура для предыдущего поля скрыта.

  • метод textFieldShouldBeginEditing возвращает ДА и затем

  • UIKeyboardWillShowNotification получен, где клавиатура для текущего поля отображена.

Однако в ОС 3.2 даже при том, что textFieldShouldBeginEditing возвращает a ДА, UIKeyboardWillShowNotification для текущего поля не получен.

Логика работает на ОС <3.2

Какие-либо идеи, где я мог бы делать неправильно?

Упомянутый ниже часть моего кода (только с двумя текстовыми полями в xib).

Я должен выполнить ряд операций в keyboardWillShow и Взгляде keyboardWillHide на различие при выполнении кода в ОС 3.2 и ОС <3.2

Кто-либо может объяснить различие в поведении?

.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");
}
10
задан WrightsCS 16 December 2011 в 20:59
поделиться