2014-11-05 64 views
1

这个问题是关系到我的另一个问题,这是解决:Dynamic UITableCellView height动态UITableCellView高度与细胞指标

我想实现动态小区的高度,这是使用此代码的工作:

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 
    } 
} 

然而,当我添加了披露指标,每个单元

cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator 

我得到这样的结果:

enter image description here

留下指标和权利,没有。

您可以检出该测试项目的GitHub库:https://github.com/ArtworkAD/DynamicCellTest

任何想法什么是错?我使用和Xcode 6.1和iOS8.1

回答

0

迅速的问题是,在我的原代码,我有:

self.tableView.estimatedRowHeight = 64 

这似乎打破了一切。我删除后,一切工作如预期。

+0

如果我旋转一个圆,我可以看到文本被剪辑。 – gabbler 2014-11-05 16:22:35

+0

@ gabbler你有另一种解决方案吗? – 2014-11-05 16:31:59

+0

是的,一个黑客解决方案,不是很完美。 – gabbler 2014-11-05 16:32:49