ios - 具有动态高度的标准 UITableViewCell

标签 ios objective-c uitableview

我想知道是否可以有一个标准 UITableViewCell有风格UITableViewCellStyleSubtitle有动态高度?

如果是,那么如何实现?

  • 我不想为单元格自定义和制作新的类和 Nib 。
  • 我已经设置了numberOfLines cell.textLabel的属性(property)和 cell.detailTextLabel0 .

好吧,如果你的 textLabel包含多行内容和detailTextLabel包含单行内容,tableView 会自动调整单元格高度。但如果它是相反的,那么它就不会!这是Apple的错误吗?或预期的功能?

下面是截图

enter image description here enter image description here

最佳答案

- (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/

相关文章:

objective-c - 检查是否存在 Objective-C 框架

iphone - 正确继承 EKEvent 类

ios - 选择后永久更改tableView中的背景单元格

iphone - 自定义单元格无法在 ios 6 的表格 View 中显示

ios - Swift - 加载另一个单元格后更新单元格中的标签?

Worklight、wikitude 和 sqlcipher 框架的 iOS 模拟器构建错误

ios - 在 Swift 中获取复杂嵌套字典/数组组合的键值

javascript - 如何使用 stringByEvaluatingJavaScriptFromString 在亚马逊上获取 ASIN 代码?

ios - Swift:将标签栏 Controller 移动到 View Controller 的顶部

ios - 为什么我的函数输出一个看起来像内存地址的随机值?