【发布时间】:2013-01-23 19:34:41
【问题描述】:
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"searchCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
searchField = (UITextField *)[cell viewWithTag:10000];
[searchField resignFirstResponder];
}
好的,我有一个标识符名称为“searchCell”的单元格。此单元格包含一个标签为 10000 的 UITextField,它会在屏幕底部弹出一个键盘。当用户触摸另一个单元格时,必须隐藏键盘,以便用户有更大的空间上下滚动。
但是,当键盘弹出并且用户触摸(选择)一个单元格时,上面的代码被调用但不起作用...... :( 看起来分配的 UITableViewCell 不是用户当前使用的那个. 我在这里做错了什么?
【问题讨论】:
-
添加 'forIndexPath' 根本没有帮助。
-
您的 nib 和 .h 文件中是否设置了代表?也这样做 => UITextField *txtFieldObj = (UITextField *)[cell viewWithTag:10000];也在 didselectRowAtIndexpath 中执行此操作,添加一个 if(yourIndexpath.row==0) 然后只辞职键盘或 if(yourindexpath!=0) 然后辞职,否则做其他事情.. [txtFieldObj resignFirstResponder];还有 NSLog(@"txtField %@",textFieldObj); // 检查是否为非空..
-
您是否设置了文本字段的委托?如果没有尝试
textfield searchfield.delegate = self;并在-(BOOL)textFieldShouldReturn:(UITextField *)textField方法中调用[searchField resignFirstResponder]; -
非常感谢你们:D
-
哦,我也应该使用 didSelectRowAtIndexPath.. 而不是 'didDeselect...' :)
标签: ios uitableview uitextfield first-responder