当我把文本字段放在单元格上时,我如何在文本字段上返回键盘。请告诉我如何解决这个问题?这是我在表格视图单元格上设置文本字段的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellidentitifier = @"cell";
UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidentitifier];
if (cell ==nil)
{
cell = [tableView dequeueReusableCellWithIdentifier:cellidentitifier];
}
else
{
[cell prepareForReuse];
}
UIImageView *imgview = [[UIImageView alloc]initWithFrame:CGRectMake(30, 10, 70, 70)];
imgview.backgroundColor = [UIColor blackColor];
[cell.contentView addSubview:imgview];
UITextField *_nameTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 10, 160, 22)];
_nameTF.placeholder =@"Client Name";
_nameTF.layer.borderWidth = 1.0;
[cell.contentView addSubview:_nameTF];
_nameTF = nil;
UITextField *_timeTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 37, 160, 22)];
_timeTF.placeholder = @"Time";
_timeTF.layer.borderWidth= 1.0;
[cell.contentView addSubview:_timeTF];
_timeTF = nil;
UITextField *_PhoneTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 64, 160, 22)];
_PhoneTF.placeholder = @"Phone";
_PhoneTF.layer.borderWidth= 1.0;
[cell.contentView addSubview:_PhoneTF];
_PhoneTF = nil;
return cell;
}
在return cell
语句之前,将委托设置为cellForRowAtIndexPath中的文本字段,如下所示。
_nameTF.delegate = self;
_timeTF.delegate = self;
_PhoneTF.delegate = self;
和
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
和您的viewcontroller
设置委托,如下所示在.h文件中
@interface myviewVC : UIViewController<UITextFieldDelegate>