ios - UITextField ResignFirstResponder 在 UIScrollView 上崩溃

标签 ios objective-c uiscrollview uitextfield resignfirstresponder

所以我的问题是,我在 ViewController 中有一个 UIScrollView,我已将 childViewController 添加到此 ViewController,并将 childViewController View 添加到 UIScrollView(由容器 ViewController 管理)。childViewController 加载并将其 View 添加到parentViewController View 层次结构,childViewController 有一个 UITextField 作为 subview (在 xib 中组装 - IBOutlets 已连接并委托(delegate)) 然后我的 childViewController 中有这个方法:

  -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touch recieved");
     [self.textField resignFirstResponder];

}

这样做会导致崩溃并显示此消息:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIScrollView _isInUpdateAnimation]: unrecognized selector sent to instance 0x8f900e0' * First throw call stack

请帮忙,tnq。

最佳答案

试试这个。

[self.view endEditing:YES];

这应该为所有可能的文本字段/ View 辞去第一响应者。

关于ios - UITextField ResignFirstResponder 在 UIScrollView 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17613303/

相关文章:

iOS 9 Swift 2 : horizontally scrollable views? Facebook 的 "suggested friends/groups"

ios - 检测 UIScrollView 上的触摸位置?

ios - 为什么我们在核心数据中使用performWait?

ios - 更改自定义 UIView 的 UILabel 文本不起作用

iphone - 从事件任务中删除应用程序会导致在尝试重新打开应用程序时崩溃

objective-c - 捕获导出/部署的 OSX 应用程序中的日志(错误、警告)

ios - 使 UIScrollView 从内部或外部滚动滚动

ios - 如何处理 UIDeviceOrientationFaceUp 和 UIDeviceOrientationFaceDown?

ios - 如何以编程方式删除 iOS 中的多个通讯录联系人?

ios - 在 NSMutableArray 的第 0 个索引处添加数据