带有单元格指示器的动态 UITableCellView 高度 [英] Dynamic UITableCellView height with cell indicator

查看:18
本文介绍了带有单元格指示器的动态 UITableCellView 高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与我解决的另一个问题有关:

任何想法有什么问题?我在 xcode 6.1 和 iOS8.1 上使用 swift

解决方案

问题是在我的原始代码中:

self.tableView.estimatedRowHeight = 64

这似乎打破了一切.删除它后,一切都按预期工作.

This question is related to another question of mine which was solved: Dynamic UITableCellView height

I wanted to achieve a dynamic cell height, which is working using this code:

import UIKit

class MyTableViewController: UITableViewController {

    var entries:Array<String> = [String]()

    override func viewDidLoad() {
        super.viewDidLoad()

        var i = 0
        while i < 20 {
            entries.append("\(i) Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor")
            i++;
        }

        self.tableView.rowHeight = UITableViewAutomaticDimension
    }

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

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        //ask for a reusable cell from the tableview, the tableview will create a new one if it doesn't have any
        let cell = self.tableView.dequeueReusableCellWithIdentifier("basic_cell", forIndexPath: indexPath) as UITableViewCell

        var label = cell.viewWithTag(13)

        if let unwrappedLabel = label as? UILabel {
            unwrappedLabel.text = self.entries[indexPath.row]
        }

        return cell
    }
}

However when I add the disclosure indicator to each cell

cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator

I get this result:

left with indicator and right without.

You can checkout the github repo of this test project: https://github.com/ArtworkAD/DynamicCellTest

Any ideas whats wrong? I am using swift with xcode 6.1 and iOS8.1

解决方案

The problem is that in my original code I had:

self.tableView.estimatedRowHeight = 64

And this seems to break everything. After I removed this everything works like expected.

这篇关于带有单元格指示器的动态 UITableCellView 高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆