ios - UITableView 中的 TextField 退出FirstResponder

标签 ios xcode uitableview tableview

我有一个带有 CustomCells 的 UITableView,其中包含一个 TextField。看看我上传的图片。

Picture1 Picture2 我希望如果我开始滚动键盘应该隐藏。

我尝试过

  - (void) scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
   NSLog(@"Got called");
   ProductTableCell *cell;
   [cell.mengeTextField  resignFirstResponder];

}

控制台日志:

2012-04-24 12:57:48.924 Book-App[21029:15803] Got called
2012-04-24 12:57:50.535 Book-App[21029:15803] Got called
2012-04-24 12:57:51.681 Book-App[21029:15803] Got called

但这对我不起作用。

还有其他解决办法吗?

最佳答案

你的问题就是Arcank所说的,cell没有定义。

- (void) scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
   NSLog(@"Got called");
   ProductTableCell *cell;// <---this cell is nil
   [cell.mengeTextField  resignFirstResponder];
}

现在,如果您无法访问该单元,则有一种作弊方法。只需将其他内容设置为第一响应者,然后立即辞职。

- (void) scrollViewWillBeginDragging:(UIScrollView *)scrollView
    {
       NSLog(@"Got called");
       [scrollView becomeFirstResponder];
       [scrollView resignFirstResponder];//You might not even need this (not sure)
    }

这可以解决您的问题。如果scrollView不能成为第一响应者,只需使用其他可以的东西。 (即兴创作)。


编辑:刚刚读过您和 Aalok Parikh 的评论,这几乎就是他想说的内容。

关于ios - UITableView 中的 TextField 退出FirstResponder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10294850/

相关文章:

ios - 如何在 TableView 单元格中添加自定义 UIButton?

ios - 具有 3 个部分的 PFQueryTableViewController

objective-c - 更改 UIViewController self.view 框架

ios - 静态 UITableView 在禁用时显示分隔线

Objective-C 语法检查器

ios - 如何从 iOS 中的 XMPP 服务器删除特定用户的聊天记录?

ios - 将音频片段以给定的偏移量插入原始音频文件中

ios - 如何仅使用 iOS 10 捕获 iOS Swift 3.0 中的崩溃

ios - 如何升级到 Xcode 4.5

ios - 更改 UITableViewCell 中元素的动态高度约束