who is issuing my UIKeyboardDidHideNotification?

[亡魂溺海] 提交于 2019-12-02 10:49:57

问题


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 ?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/19907698/who-is-issuing-my-uikeyboarddidhidenotification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!