我想知道是否可以有一个标准 UITableViewCell
有风格UITableViewCellStyleSubtitle
有动态高度?
如果是,那么如何实现?
- 我不想为单元格自定义和制作新的类和 Nib 。
- 我已经设置了
numberOfLines
cell.textLabel
的属性(property)和cell.detailTextLabel
至0
.
好吧,如果你的 textLabel
包含多行内容和detailTextLabel
包含单行内容,tableView 会自动调整单元格高度。但如果它是相反的,那么它就不会!这是Apple的错误吗?或预期的功能?
下面是截图
最佳答案
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
cell.textLabel.text = @"Title";
cell.detailTextLabel.text = @"SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text";
cell.detailTextLabel.numberOfLines = 0;
return cell;
}
关于ios - 具有动态高度的标准 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29791169/