who is issuing my UIKeyboardDidHideNotification?

2019-03-01 04:27发布

I want to register to UIKeyboardDidHideNotification that only my UIViewController is issuing.

When I do :

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:self];

I'm not getting any calls to keyboardDidHide: and when I do :

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];

I'm getting calls from all the other view controller as well as my own.

How can I register to the UIKeyboardDidHideNotification raised only by a specific view controller ?

2条回答
Rolldiameter
2楼-- · 2019-03-01 05:05

You have no way to register for a UIKeyboardDidHideNotification coming from a specific controller.

If using UIKeyboardWillHideNotification, you could check if one of the UITextView inside your controller is the first responder.

Using UIKeyboardDidHideNotification I guess you need to use delegate methods for all your UITextView and save the last one that was edited. I don't think of any other alternative.

Else, if the issue is to perform the method called by UIKeyboardDidHideNotification only on the visible controller, the solution by @sviatoslav-yakymiv works well.

查看更多
该账号已被封号
3楼-- · 2019-03-01 05:12

Object for UIKeyboardDidHideNotification is always nil. Try to add observer in viewWillAppear and remove in viewDidDisapper methods.

查看更多
登录 后发表回答