加快键盘关闭速度或等待完成
我在模态 UINavController 中的保存按钮遇到问题。当我按下保存按钮时,如果键盘仍然打开,我将关闭键盘,验证文本字段中的数据,然后在发送信息时显示 UIProgressView。
我的问题是键盘没有足够快地让开,所以当需要显示 UIProgressView 时键盘仍然处于打开状态,并且它被添加到我的视图底部,看起来很愚蠢。
我可以按返回键,然后键盘掉落,然后按保存,没有问题。但是,如果用户跳过键盘返回键并直接转到右上角的保存按钮,我就会遇到问题。
理想情况下,我想实现一个简短的等待语句,让它消失。或者在延迟后执行我的验证,但我尝试过的任何方法都不起作用。请帮忙。
代码示例:
// end edit mode - should kill all keyboards
[[self.tableView superview] endEditing:YES];
// make sure everything is entered correctly and validates
[self validateEntryFields]; // keyboard not gone when this finishes
if (valid) { // progress view shows up towards bottom of view
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"Adding User";
HUD.detailsLabelText = @"Please Wait";
[HUD showWhileExecuting:@selector(sendNewUserInformation) onTarget:self withObject:nil animated:YES];
}
I'm having an issue with my save button in a modal UINavController. When I press the save button, I'm dismissing the keyboard if it is still up, validating the data from the text fields, then showing a UIProgressView while I send my info out.
My problem is that the keyboard isn't getting out of the way fast enough, so keyboard is still up when it is time to show the UIProgressView and it is getting added towards the bottom of my view and it looks stupid.
I can hit the return key, and the keyboard drops, then press save, no issues. But if the user skips the keyboard return key and goes right for the top right save button, I have issues.
Ideally I'd like to implement a short wait statement for it to drop out of sight. Or perform my validation after a delay, but nothing I have tried is working. Please help.
Code Example:
// end edit mode - should kill all keyboards
[[self.tableView superview] endEditing:YES];
// make sure everything is entered correctly and validates
[self validateEntryFields]; // keyboard not gone when this finishes
if (valid) { // progress view shows up towards bottom of view
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"Adding User";
HUD.detailsLabelText = @"Please Wait";
[HUD showWhileExecuting:@selector(sendNewUserInformation) onTarget:self withObject:nil animated:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用键盘通知(这将是比基于计时器更正确的解决方案):
并在
keyboardDidHide:
方法中显示您的进度视图。You may use keyboard notification (it would be more correct solution than based on timer):
And show your progress view in
keyboardDidHide:
method.如果小延迟有效,您可以在验证和 if 语句之间尝试以下代码,您可以在其中决定是否显示进度视图。
您可以使用 NSTimer 对象:
并将代码添加到如下方法中:
如果我正确理解了您的问题,那么应该可以解决问题。
If a small delay would be working you could try the following code between your validation and your if statement where you decide whether or not you will showing the progress view.
You can use the NSTimer object:
And add your code into a method like:
If I understood correctly your problem that should work.