Ios SizeToFit在单元中垂直居中的UITextView上
[已解决] 我的错误。。。详细信息是UILabel,而不是UITextView。sizeToFit不会调整UILabel的大小。用UITextView替换UILabel可以解决我的问题Ios SizeToFit在单元中垂直居中的UITextView上,ios,uitableview,constraints,Ios,Uitableview,Constraints,[已解决] 我的错误。。。详细信息是UILabel,而不是UITextView。sizeToFit不会调整UILabel的大小。用UITextView替换UILabel可以解决我的问题 我有一个固定高度的自定义单元格,其中包含了垂直居中视图(称为“内容”)的所有约束,该视图包含标题和说明。内容视图层次结构是: 图标 标题 内容视图 标题标签 详细信息UITextView 页脚 当我在interface builder中测试“details”的值时,预览(xCode 6)中的一切都正常:
我有一个固定高度的自定义单元格,其中包含了垂直居中视图(称为“内容”)的所有约束,该视图包含标题和说明。内容视图层次结构是:
- 图标
- 标题
- 内容视图
- 标题标签
- 详细信息UITextView
- 页脚
sizeToFit
时,UITextView的大小会正确调整,但约束不会更新。请参见下面的cellForRowAtIndexPath
code。我错过了什么
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// get a cell
QZSetupPartyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PackCell" forIndexPath:indexPath];
// fill the current cell with the current pack
QZPack *pack = self.party.packs[indexPath.row];
// set pack title
cell.title.text = pack.json[@"title"];
// resize textview to its content
cell.details.text = pack.json[@"desc"];
[cell.details sizeToFit];
// async load of the icon
[pack loadIconWithCompletion:^(UIImage *image) {
cell.icon.image = image;
[cell setNeedsLayout];
}];
// and recompute the cell constraints
[cell layoutIfNeeded];
[cell setNeedsDisplay];
return cell;
}
你们能添加一个xib的截图吗?很抱歉,并没有足够的声誉这么做。