2010-08-10 8 views
0

UITableViewCell 안에 UITextField가 있습니다. textField가 반환되기를 원하지만 뭔가 잘못되었습니다.iPad UITextField가 반환되지 않습니다.


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
if (indexPath.section == 0) { 
     if (indexPath.row == 0) { 
      cell.selectionStyle = UITableViewCellSelectionStyleNone; 
      usernameField = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, cell.contentView.frame.size.width, cell.contentView.frame.size.height)]; 
      usernameField.adjustsFontSizeToFitWidth = YES; 
      usernameField.placeholder = @"Username"; 
      usernameField.contentVerticalAlignment = UIControlContentVerticalAlignmentTop; 
      usernameField.backgroundColor = [UIColor clearColor]; 
      usernameField.keyboardType = UIKeyboardTypeDefault; 
      usernameField.autocapitalizationType = UITextAutocapitalizationTypeNone; 
      usernameField.autocorrectionType = UITextAutocorrectionTypeNo; 
      usernameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
      usernameField.returnKeyType = UIReturnKeyDone; 
      usernameField.delegate = self; 
      usernameField.clearButtonMode = UITextFieldViewModeAlways; 
      [usernameField setEnabled:YES]; 
      [cell addSubview:usernameField]; 
      [usernameField becomeFirstResponder]; 
      [usernameField release];    
     } 
    } 
} 

- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
    [textField resignFirstResponder]; 
    return YES; 
} 

가 나는 또한

감사를 UITextFieldDelegate 내 클래스를 구현 : 여기 내 코드입니다!

답변

0

방금 ​​비슷한 문제가있었습니다. 하위 클래스 UITableViewCell 훨씬 깨끗한 접근 방식입니다. 아래 링크는 좋은 출발점이 될 것입니다.

관련 문제