swift – 默认UITableView Cell自动高度

我有一个UITableViewController,其样式为uitableviewcellstylesubtitle,其中字幕标签的numberoflines = 0

如果我这样做

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 44.0

细胞不做自动高度,它真的是真的 – 你不能在认的样式细胞上使用它吗?

编辑:

人口简单

override func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell",forIndexPath: indexPath)
    let thisHelpArticle = helpObjects[indexPath.section]

    cell.textLabel!.text = thisHelpArticle.helpHeadline
    cell.detailTextLabel!.text = thisHelpArticle.helpDescription

    return cell
}
UPDATE!
为了使认单元格子标题自动调整单元格,您必须将两个标签的行数设置为0.否则它不起作用.奇怪的.
cell.textLabel?.numberOfLines = 0
cell.detailTextLabel?.numberOfLines = 0

您可以自动调整认的sytled单元格大小.在最简单的形式中,我有以下代码.这是自动调整认样式字幕单元格的大小.

class ViewController: UIViewController {

    @IBOutlet var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.dataSource = self
        tableView.delegate = self
        tableView.rowHeight = UITableViewAutomaticDimension
        tableView.estimatedRowHeight = 44
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // dispose of any resources that can be recreated.
    }
}

extension ViewController: UITableViewDataSource {
    func tableView(tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
        return 2
    }

    func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell",forIndexPath: indexPath)
        let thisHelpArticle = "Lorem ipsum dolor sit amet,vel porttitor blandit,aliquam tristique vestibulum,enim vel eros fames id,in gravida vestibulum gravida tempor,et vel libero sed mauris. Suspendisse ut placerat viverra dictum,ante ante vel ut vestibulum sollicitudin phasellus. Dictumst adipiscing adipiscing nisl,fusce ut. Ante wisi pellentesque,et aliquam rhoncus eget convallis quam voluptate,ut nec quis,soDales ullamcorper elementum pellentesque sagittis vitae,dolor justo fermentum amet risus. Eu placerat ultricies. Ipsum soDales,massa elit,in neque,sed penatibus gravida,cursus eget. Ut tincidunt at eu,wisi dis vel penatibus eget,volutpat ligula vel tortor morbi feugiat,dui et eiusmod dis sociis. Iaculis lorem molestie laoreet sit,orci commodo,fusce vestibulum sapien,quisque egestas maecenas sed rem in nisl."

        cell.textLabel?.numberOfLines = 0
        cell.detailTextLabel?.numberOfLines = 0

        cell.textLabel!.text = thisHelpArticle
        cell.detailTextLabel!.text = thisHelpArticle

        return cell
    }
}

extension ViewController: UITableViewDelegate {

}

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...