[英]Execute code after method has finished
I need to execute some code after I know the keyboard is hidden. 我知道键盘被隐藏后,需要执行一些代码。
Ive been looking in to blocks but I'm just not understanding how they work enough to do this... 我一直在寻找障碍物,但我只是不了解它们如何有效地做到这一点...
All I want to do is run [self hidekeyboard] then when that is complete (and the keyboard fully hidden) then I want to call a delegate. 我想做的就是运行[self hidekeyboard],然后完成该操作(并且键盘完全隐藏),然后我要调用一个委托。
What is the best way to handle this and how? 处理此问题的最佳方法是什么?
You want to use the UIKeyboardDidHide notification and run your code in there. 您要使用UIKeyboardDidHide通知并在其中运行代码。 Here is the link in the docs...
这是文档中的链接...
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html 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];
And the onKeyboardDidHide
: 和
onKeyboardDidHide
:
-(void)onKeyboardDidHide:(NSNotification *)notification
{
// execute what you want.
}
Register a listener for the UIKeyboardDidHideNotification
using the NSNotificationCenter
class. 使用
NSNotificationCenter
类为UIKeyboardDidHideNotification
注册一个侦听器。
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(keyboardHidden:)
name:UIKeyboardDidHideNorification
object:nil];
- (void)keyboardHidden:(NSNotification *)notif
{
// do stuff
}
(Don't forget to remove the observer in - dealloc
so that no messages will erroneously be sent to deallocated objects.) (不要忘记在
- dealloc
删除观察者,这样就不会有错误的消息发送到已释放的对象。)
You probably want to register to receive notifications of UIKeyboardDidHideNotification. 您可能想要注册以接收UIKeyboardDidHideNotification的通知。
http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.