将textfield添加到表格单元格

时间:2011-06-28 17:26:59

标签: iphone

我正在尝试将文本字段添加到表格单元格中。任何人都可以请更正此代码

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];

由于

1 个答案:

答案 0 :(得分:4)

看看这个例子。

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

请务必在您的标头文件中添加UITextFieldDelegate

相关问题