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

问题描述

|| 我在iOS下的表上工作,我添加了两个单元格,每个单元格都添加一个UITextField作为子视图。摘录:
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];
怎么了?当我进入表格的编辑模式时,我希望每个单元格都会调整大小以使红色减号可见,并且UITextField会向右移动以与单元格本身保持对齐,就像其他组件一样。但这不会发生。 另外,我尝试使用
UIViewAutoresizingFlexibleLeftMargin
UIViewAutoresizingFlexibleRightMargin
UIViewAutoresizingFlexibleWidth
的各种组合来更改
autoresizingMask
参数,但没有成功。 我在这里做错什么了吗?是否应该更改将文本字段添加为子视图的方式? 谢谢!     

解决方法

将您的视图添加到单元格的contentView中:
[cell.contentView addSubview:t];