pa12
pa12

Reputation: 1503

Adding textfield to table cell

I am trying to add a textfield to a table cell. Can anyone please correct this code

aCell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"UserIDCell"] autorelease];
                    aCell.textLabel.text = @"User Name";
                    aCell.selectionStyle = UITableViewCellSelectionStyleNone;
                    UITextField *user_ID_TextField1 = [[UITextField alloc] initWithFrame:CGRectZero];
                    aCell.accessoryView = user_ID_TextField1;
                    [user_ID_TextField1 release];

Thanks

Upvotes: 2

Views: 4634

Answers (1)

Legolas
Legolas

Reputation: 12325

Look at this example.

    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(110, 10, 185, 30)];
    textField.clearsOnBeginEditing = NO;
    textField.textAlignment = UITextAlignmentRight;
    textField.delegate = self;  
    [aCell.contentView addSubview:textField];

Remember to add UITextFieldDelegate to your header file.

Upvotes: 4

Related Questions