2014-10-09 68 views
0

我如何返回textfield上的鍵盤,而我已經把textfield放在cell.contentview上,我正在使用textfieldshouldreturn method但它不工作所以請告訴我如何解決它呢? 這是對的tableview細胞我的一套文本框代碼如何在文本字段上返回鍵盤,同時在ios中的tableview單元上的文本字段

- (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 [email protected]"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; 
} 
+0

的2種方式來擺脫鍵盤的是告訴視圖編輯結束像這樣:[self.view endEditing:YES];或者告訴文本視圖退出第一響應者[textView resignFirsResponder](如果你想以這種方式解除,可以在textfieldshouldreturn中調用) – DBoyer 2014-10-09 04:55:43

+0

爲所有文本字段設置委託自身,並在textfieldshouldreturn委託操作中設置resignfirstresponder。 – Max 2014-10-09 05:33:26

回答

1

組代表到的cellForRowAtIndexPath文本框下面,以前return cell聲明。

_nameTF.delegate = self; 
_timeTF.delegate = self; 
_PhoneTF.delegate = self; 

-(BOOL)textFieldShouldReturn:(UITextField *)textField{ 

    [textField resignFirstResponder]; 

    return YES; 
} 

和下面的viewcontroller組代表在.h文件中

@interface myviewVC : UIViewController<UITextFieldDelegate> 
相關問題