在didSelectRowAtIndexPath上的UITextView resignFirstResponder

时间:2013-08-11 20:14:08

标签: ios objective-c uitextview

我在IB静态UITableView中,当我点击单元格时,我想要隐藏键盘。 当isFirstResponderUITextField时,没关系! 但是当UITextView不起作用时:(

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [publicationTextView resignFirstResponder];
    //[self.view endEditing:YES];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

1 个答案:

答案 0 :(得分:0)

如果要隐藏文本字段的键盘,请在将子视图添加到单元格时将设置isEditable设置为“NO” I,E


     //- (UITableViewCell *)tableView:(UITableView *)tableView   cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    UITextView *aTv = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, 200, 300)];
    aTv.text = @"textView";
    aTv.delegate = self;
    [aTv setEditable:NO]; //avoid appearing of key board when tap on the text field
    [cell addSubview:aTv];


//希望这有帮助