ios – Static UITableView,在Swift中创建一个具有动态高度的单元格

我有一个静态UITableView有12行,11行我知道高度需要是什么.

我有一个UILabel,它有动态文本,位于12行内,我如何根据UILabel中的文本制作一个单元格的动态高度.

我在viewDidLoad中尝试了以下代码,但它没有用.行保持相同的高度.我还为UILabel设置了lines = 0

tableView.estimatedRowHeight = 100.0
    tableView.rowHeight = UITableViewAutomaticDimension

解决方法

你试过这个吗?
override func tableView(tableView: UITableView,heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if (indexPath.row < 11) {
        // Everything starts at 0,so this covers 0-10
        // Whatever your cell height is
        return <#fixedCellHeight#>
    } else {
        // This is your 12th cell (indexPath.row 11),as we start counting at 0
        return UITableViewAutomaticDimension
    }
}

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...