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] initWith开发者_Python百科Frame:CGRectZero];
aCell.accessoryView = user_ID_TextField1;
[user_ID_TextField1 release];
Thanks
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.
精彩评论