ios - 动态单元格高度尺寸不起作用

标签 ios iphone swift cocoa-touch ios8

我正在使用 swift 2.0 并尝试在没有自定义单元原型(prototype)的情况下创建表格 View 。我写的是:

override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.backgroundColor = UIColor(patternImage: UIImage(named: "ViewBg.png")!)

    self.tableView.estimatedRowHeight = 100.0
    self.tableView.rowHeight = UITableViewAutomaticDimension

    Alamofire.request(.GET, "https://****.herokuapp.com/user/000", parameters: nil)
      .responseJSON { response in
        let fortuneHistoryJson = JSON(response.result.value!)["fortuneHistory"]

        for var index = 0; index < fortuneHistoryJson.count; ++index {
          let FortuneHistoryItem = FortuneHistory()
          FortuneHistoryItem.content = fortuneHistoryJson[index]["fortune"]["content"].string
          FortuneHistoryItem.date = fortuneHistoryJson[index]["createdAt"].string
          FortuneHistoryItem.imageUrl = fortuneHistoryJson[index]["cupPicture"].string
          self.fortuneHistoryData.append(FortuneHistoryItem)
        }
        self.tableView.reloadData();
    }
  }

  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return fortuneHistoryData.count
  }

  func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableViewAutomaticDimension

  }

  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Cell")
    cell.textLabel!.text = self.fortuneHistoryData[indexPath.row].date;
    cell.detailTextLabel!.text = self.fortuneHistoryData[indexPath.row].content
    cell.textLabel!.numberOfLines = 0
    cell.detailTextLabel!.numberOfLines = 0

    cell.imageView!.kf_setImageWithURL(NSURL(string: self.fortuneHistoryData[indexPath.row].imageUrl )!, placeholderImage: UIImage(named: "ViewBg.png")!)
    var itemSize: CGSize = CGSizeMake(100, 100)
    UIGraphicsBeginImageContextWithOptions(itemSize, false, UIScreen.mainScreen().scale)
    var imageRect: CGRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height)
    cell.imageView!.image!.drawInRect(imageRect)
    cell.imageView!.image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()


    return cell
  }

我希望将单元格放大detailTextLabel大小,但它们保持不变并且重叠:http://i61.tinypic.com/1shb3b.jpg

最佳答案

除了像 @jrc 提到的那样创建自定义单元原型(prototype)之外,我找不到任何解决方案。因此,解决方案是创建自定义单元原型(prototype)并使用自动布局。

关于ios - 动态单元格高度尺寸不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33206000/

相关文章:

iphone - 如何构建原生 Web 应用程序?

ios - iOS 上的 Sqlite 数据库查询仅更新一个字段

ios - 为什么Deep Link Web URL查询为空

ios - 贯穿整个应用程序的运行方法 - IOS

ios - UITableViewController隐藏导航栏[搜索栏]

iphone - UIButton 标签为零

iphone - Facebook SDK 集成 - 使用 View Controller 而不是应用程序委托(delegate)

iphone - 在 objective-c 中释放 int

ios - 异步 swift 函数是否应该保留对该对象的强引用?

swift - 尝试编写一个通用函数来将 JSON 解析为可编码的结构