【发布时间】:2013-07-23 20:34:18
【问题描述】:
我试图让我的UITableViewCell 根据textview 正确调整大小,该textview 根据其文本动态调整大小。但是我不能让他们一起工作。以下是我到目前为止所拥有的?现在单元格高度是正确的,但 textView 没有根据 contentSize.height 调整大小。
- (void)viewDidLoad
{
[super viewDidLoad];
// Set the label properties!
self.titleLabel.text = self.releaseTitle;
self.pubDateLabel.text = self.pubDate;
self.attachmentsLabel.text = [NSString stringWithFormat:@"%lu", (unsigned long)self.attatchments.count];
self.contentTextView.text = self.summary;
}
- (void)viewWillAppear:(BOOL)animated
{
}
- (void)viewDidAppear:(BOOL)animated
{
[self.tableView reloadData];
// Set the proper height of the content cell of the text
CGRect frame = self.contentTextView.frame;
frame.size.height = self.contentTextView.contentSize.height;
self.contentTextView.frame = frame;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return self.contentTextView.contentSize.height;
}
【问题讨论】:
-
试试cocoacontrols.com/controls/autoresizingeditabletableviewcell 它已经过测试并且工作正常。
-
我宁愿不必子类化 UITableViewCell,尤其是在 iOS7 出现时...
-
在调用 viewWillAppear: 和 viewDidAppear: 时不要忘记添加 [super viewWillAppear:animated] 和 [super viewDidAppear:animated] ;)
-
能否尝试在 contentTextView 中调用 sizeToFit 方法?
-
不,这不起作用。
标签: ios uitableview uitextview tableview frame