我的UITextView上没有调用keyboardWasShown方法

bit*_*moe 3 iphone cocoa-touch objective-c ios

我有一个UITextView,我实现了一个keyboardWasShownMethod,如下所示:

(void)keyboardWasShown:(NSNotification*)aNotification {
    NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    CGRect bkgndRect = inkTextField.superview.frame;
    bkgndRect.size.height += kbSize.height;
    [inkTextField.superview setFrame:bkgndRect];
    [inkScroller setContentOffset:CGPointMake(0.0, inkTextField.frame.origin.y-kbSize.height) animated:YES];
     inkTextField.frame=CGRectMake(1, -5, 285, 221);
    NSLog(@"Called keyBoardWasShwon");
}
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,当我的键盘出现时它不会被调用.此方法与UITextView位于同一类中,UITextView在.h文件中声明并在XIB中连接.可能是什么原因造成的?

Emp*_*ack 8

你是否为UIKeyboardWillShowNotification添加了观察者?

[[NSNotificationCenter defaultCenter] 
                     addObserver:self 
                        selector:@selector(keyboardWasShown:) 
                            name:UIKeyboardWillShowNotification 
                          object:nil];
Run Code Online (Sandbox Code Playgroud)