2010-03-21 21 views

Trả lời

5

Thêm UITextField như một subview của contentView của UITableViewCell:

[mycell.contentView addSubview:view]; 
1

Đây là cách tôi đã triển khai nó vào ứng dụng của mình, tuy nhiên bạn rõ ràng sẽ cần phải thay đổi một vài điều. Hi vọng điêu nay co ich.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Configure the cell. 

//adding all the UITextField's to the UITableViewCell is a pain in the ass. Pretty sure this is correct though. 

if ([indexPath section] == 0) { 
    tUser = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)]; 
    tUser.adjustsFontSizeToFitWidth = YES; 
    tUser.textColor = [UIColor blackColor]; 

    tPass = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)]; 
    tPass.adjustsFontSizeToFitWidth = YES; 
    tPass.textColor = [UIColor blackColor]; 

    if ([indexPath section] == 0) { 
     if ([indexPath row] == 0) { 
      tUser.placeholder = @"@JohnAppleseed"; 
      tUser.keyboardType = UIKeyboardTypeEmailAddress; 
      tUser.returnKeyType = UIReturnKeyNext; 
     } 
     if ([indexPath row] == 1) { 
      tPass.placeholder = @"Required"; 
      tPass.keyboardType = UIKeyboardTypeDefault; 
      tPass.returnKeyType = UIReturnKeyDone; 
      tPass.secureTextEntry = YES; 
     } 
    } 

    tUser.backgroundColor = [UIColor whiteColor]; 
    tUser.autocorrectionType = UITextAutocorrectionTypeNo; 
    tUser.autocapitalizationType = UITextAutocapitalizationTypeNone; 
    tUser.textAlignment = UITextAlignmentLeft; 

    tPass.backgroundColor = [UIColor whiteColor]; 
    tPass.autocorrectionType = UITextAutocorrectionTypeNo; 
    tPass.autocapitalizationType = UITextAutocapitalizationTypeNone; 
    tPass.textAlignment = UITextAlignmentLeft; 

    tUser.clearButtonMode = UITextFieldViewModeNever; 
    tPass.clearButtonMode = UITextFieldViewModeNever; 

    [tUser setEnabled:YES]; 
    [tPass setEnabled:YES]; 

    //[tUser release]; 
    //[tPass release]; 
} 
if ([indexPath section] == 0) { // Email & Password Section 
    if ([indexPath row] == 0) { // Email 
     cell.textLabel.text = @"Username"; 
     [cell addSubview:tUser]; 
     [tUser setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"twitter_name_preference"]]; 
    } 
    else { 
     cell.textLabel.text = @"Password"; 
     [cell addSubview:tPass]; 
     [tPass setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"twitter_pass_preference"]]; 
    } 
} 
return cell; } 

Hy vọng điều đó sẽ hữu ích.

Các vấn đề liên quan