繁体   English   中英

方法完成后执行代码

[英]Execute code after method has finished

我知道键盘被隐藏后,需要执行一些代码。

我一直在寻找障碍物,但我只是不了解它们如何有效地做到这一点...

我想做的就是运行[self hidekeyboard],然后完成该操作(并且键盘完全隐藏),然后我要调用一个委托。

处理此问题的最佳方法是什么?

您要使用UIKeyboardDidHide通知并在其中运行代码。 这是文档中的链接...

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html

[[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删除观察者,这样就不会有错误的消息发送到已释放的对象。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM