iphone - ResignFirstResponder 不工作

标签 iphone objective-c resignfirstresponder

-(IBAction)settings:(id)sender
{
    [mileagerate resignFirstResponder];

    [mainView bringSubviewToFront:mileageView];
    mainView.hidden=TRUE;

    [UIView beginAnimations:@"Settings" context:nil];
    [UIView setAnimationDuration:1.0];
    [mainView setFrame:CGRectMake(0, 0, 320, 460)];
    [UIView commitAnimations];
    mileagerate.text = [[NSUserDefaults standardUserDefaults] valueForKey:@"savedstring"];

    mileageView.hidden=FALSE;
}

我在我的应用程序的各个地方使用了 resign first responder。但是当我单独点击这个按钮时,键盘并没有消失。如果我点击键盘上的返回键,输入的值就会消失。

最佳答案

如果您不知道要退出哪个 textfield,请在您的方法中使用以下代码行:

swift

self.view.endEditing(true)//resign current keyboard 

Objective-C

[self.view endEditing:YES]; //resign current keyboard 

编辑:注意:它将从您当前的 View 中退出keybord

关于iphone - ResignFirstResponder 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12639607/

相关文章:

ios - UITableView reloadData 自动调用resignFirstResponder

iphone - 如何在 iPad 中自动旋转期间重新排列 View

ios - 如果在数组中找不到任何内容,为什么此循环会导致崩溃

iphone - Xcode:如何构建仅横向的 iPhone 程序

ios - 如何从 ios 中的应用程序文件夹中按日期对 uiimages 进行排序

objective-c - 在我按返回键并选择另一个选项后,表格没有刷新。始终与第一个选择相同的表

iphone - 加快键盘关闭速度或等到它完成

IOS 7 UITextField resignFirstResponder 坏

iphone - 配置文件与应用程序标识符不匹配

iphone - iPhone SDK 中的透明按钮