【发布时间】:2013-10-06 16:24:47
【问题描述】:
我有一个UITableview 有多个可重复使用的 TableViewCells。
在一个单元格中,我有一个UITextView,它会调整自身大小以适应其内容。现在我“只是”必须调整 TableViewCell 的 contentView 的大小,这样我就可以阅读 while 文本。我已经试过了:
cell2.contentView.bounds.size.height = cell2.discriptionTextView.bounds.size.height;
或者:
cell2.contentView.frame = CGRectMake(0, cell2.discriptionTextView.bounds.origin.y,
cell2.discriptionTextView.bounds.size.width,
cell2.discriptionTextView.bounds.size.height);
在方法中:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath {}
但它不会起作用。
有人知道怎么做吗?
新代码:
@implementation AppDetail
CGFloat height;
…
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{…
cell2.TextView.text = self.text;
[cell2.TextView sizeToFit];
height = CGRectGetHeight(cell2.TextView.bounds);
…
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
return 143;
}
if (indexPath.row == 1) {
return height;
}
return 0;
}
【问题讨论】:
标签: ios objective-c uitableview