UITextField在编辑UITableViewCell时不会自动调整大小

问题描述:

我正在iOS下工作,我添加了几个单元格,每个单元格都有一个UITextField作为子视图添加。摘录:UITextField在编辑UITableViewCell时不会自动调整大小

UITextField *t = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 5.0, 220.0, 20.0)]; 
// here I set properties for t ... 
t.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth; 
[cell addSubview:t]; 
cell.autoresizeSubviews = YES; 

// if needed, I set the UIImageView for the cell 
if (...) { 
    cell.imageView.image = [UIImage imageNamed:@"myimage.png"]; 
    t.frame = CGRectOffset(text.frame, 33, 0); 
} 

[t release]; 

会发生什么?当我进入tabel的编辑模式时,我期望每个单元格都将调整大小以使红色减号可见,并且UITextField将向右移动以保持与单元格本身对齐,如同其他组件。但是这不会发生。

而且,我试图改变使用UIViewAutoresizingFlexibleLeftMarginUIViewAutoresizingFlexibleRightMarginUIViewAutoresizingFlexibleWidth各种组合autoresizingMask PARAM,但没有成功。

我在这里做错了什么?我应该改变将文本字段添加为子视图的方式吗?

谢谢!

添加您欣赏到细胞的内容查看:

[cell.contentView addSubview:t]; 
+0

我没有尝试只是......我尝试添加到'textLabel',到'detailTextLabel' ...爽,谢谢您! – marzapower 2011-05-24 12:41:09