[英]Execute code after method has finished
我知道键盘被隐藏后,需要执行一些代码。
我一直在寻找障碍物,但我只是不了解它们如何有效地做到这一点...
我想做的就是运行[self hidekeyboard],然后完成该操作(并且键盘完全隐藏),然后我要调用一个委托。
处理此问题的最佳方法是什么?
您要使用UIKeyboardDidHide通知并在其中运行代码。 这是文档中的链接...
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onKeyboardDidHide:) name: UIKeyboardDidHideNotification object:nil];
和onKeyboardDidHide
:
-(void)onKeyboardDidHide:(NSNotification *)notification
{
// execute what you want.
}
使用NSNotificationCenter
类为UIKeyboardDidHideNotification
注册一个侦听器。
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(keyboardHidden:)
name:UIKeyboardDidHideNorification
object:nil];
- (void)keyboardHidden:(NSNotification *)notif
{
// do stuff
}
(不要忘记在- dealloc
删除观察者,这样就不会有错误的消息发送到已释放的对象。)
您可能想要注册以接收UIKeyboardDidHideNotification的通知。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.