2010-03-21 4 views

Antwort

5

die UITextField als Subview der contentView des UITableViewCell hinzufügen:

[mycell.contentView addSubview:view]; 
1

Dies ist, wie ich es in meine Anwendung implementiert habe, aber Sie müssen natürlich ein paar Dinge ändern. Hoffe das hilft.

- (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; } 

Ich hoffe, es hilft.

Verwandte Themen