Reputation: 1503
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
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