【问题标题】:Is it possible to change static cell height in iOS 7 using Swift?是否可以使用 Swift 在 iOS 7 中更改静态单元格高度?
【发布时间】:2015-03-24 22:21:55
【问题描述】:

我知道有人可能会回答这个问题,但我还没有找到解决方案。

我正在尝试使用 Swift 通过代码更改静态单元格的高度。我正在使用这种方法 func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat

但单元格大小不会根据标签的内容而改变。这就是我所拥有的:

@IBOutlet weak var testDetailsLabel: UILabel!
@IBOutlet weak var testDetailsCell: TestDetailsTableViewCell!

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

    if indexPath.section == 1 && indexPath.row == 0 {
        self.testDetailsCell.descriptionLabel?.text = self.test?.details
        self.testDetailsCell.setNeedsLayout()
        self.testDetailsCell.layoutIfNeeded()
        self.testDetailsCell.bounds = CGRectMake(0.0, 0.0, tableView.bounds.width, self.testDetailsCell.bounds.height)
        self.testDetailsCell.setNeedsLayout()
        self.testDetailsCell.layoutIfNeeded()

        let size = self.testDetailsCell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize) as CGSize!

        return size.height + 1
    }

    return super.tableView(tableView, heightForRowAtIndexPath: indexPath)
}

有人知道是否可以更改静态单元格的高度大小吗?

也许约束是问题所在?我有两侧约束,顶部、底部和高度 >= 约束。

【问题讨论】:

    标签: ios uitableview swift ios7


    【解决方案1】:

    我昨晚也在与这个搏斗。我正在 iOS8 中开发,所以如果这在 ios 7 中不起作用,我深表歉意,但我所做的只是为表本身连接一个 IBOutlet,并在我的 viewDidLoad() 方法中使用以下代码:

    @IBOutlet var logInTable: UITableView!
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            logInTable.rowHeight = 50  //Make table cells fixed height
    
    }
    

    我希望这会有所帮助。

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-01
      • 2016-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多