简体   繁体   English

iOS)在UITableView的单元格中隐藏键盘

[英]iOS) HIding Keyboard in a cell in UITableView

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"searchCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    searchField = (UITextField *)[cell viewWithTag:10000];

    [searchField resignFirstResponder];
}

Okay, I have a cell with a identifier name of "searchCell". 好的,我有一个标识符名称为“ searchCell”的单元格。 This cell contains one single UITextField with tag 10000 that pops up a keyboard on the bottom of the screen. 该单元格包含一个带有标签10000的UITextField,该UITextField在屏幕底部弹出一个键盘。 When a user touches another cell, the keyboard must be hidden so that the user can have larger space to scroll up and down. 当用户触摸另一个单元格时,必须隐藏键盘,以便用户可以有更大的空间上下滚动。

However, when a keyboard has popped up and a user touches(select) a cell, the code above is called but not working... :( It seems like the assigned UITableViewCell is not the one that the user is currently using. What am I doing wrong here? 但是,当键盘弹出并且用户触摸(选择)一个单元格时,上面的代码将被调用但不起作用... :(似乎分配的UITableViewCell不是用户当前正在使用的那个。我在这里做错了吗?

  1. Make your class a delegate of UITextField 使您的类成为UITextField的委托
  2. Go to the Storyboard file, click on the text field and go to connections inspector 转到情节提要文件,单击文本字段,然后转到连接检查器
  3. Under outlets, connect the delegate to the View Controller 在出口下,将委托连接到View Controller
  4. Run it in simulator. 在模拟器中运行。 It will work 会工作的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM