我正在为列表制作一个视图。它具有动态的字幕长度。所以我使用了UITableViewAutomaticDimension属性。我没有应用任何约束,因为这两个标签都是表视图单元格属性,因此不需要创建新的自定义单元格。UITableViewAutomaticDimension应用于字幕表格视图单元格不能正常工作
但运行这个项目后,我标记了UITableViewAutomaticDimension不能正常工作。我不知道我做错了什么。我的代码是像下面
视图做负载
@IBOutlet weak var tblabc: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tblabc.separatorColor = UIColor.clearColor()
tblabc.estimatedRowHeight = 44
tblabc.rowHeight = UITableViewAutomaticDimension
// Do any additional setup after loading the view.
}
表视图委托和数据源
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell = tableView.dequeueReusableCellWithIdentifier("Cell")
if (cell == nil)
{
cell = UITableViewCell(style: .Subtitle, reuseIdentifier: "Cell")
cell?.selectionStyle = .None
cell?.detailTextLabel?.font = _SETREGULARFONT_KARLA(IS_IPAD ? 19:15)
cell?.textLabel?.font = _SETBOLDFONT_KARLA(IS_IPAD ? 17:13)
cell?.detailTextLabel?.textColor = getColorFromRGB(120, G: 132, B: 158, A: 1.0)
cell?.detailTextLabel?.numberOfLines = 0
cell?.detailTextLabel?.lineBreakMode = .ByTruncatingTail
cell?.selectionStyle = .None
}
cell?.textLabel?.text = "Testing" + "\(indexPath.row)"
cell?.detailTextLabel?.text = "tesfhjdsfskdfhjkfhdjskfhsjkdfhdjsxdfgfjljkgjfklgfhsdjfhjkdshfdjskfhdjfjkfhafyhdsifjhdjksfbshdjkfkhdksjfhdjsfyhds8ufdhsfjkhdsfjhdfudsiufhdsfh"
cell?.imageView?.image = UIImage(named: "new_temp")
return cell!
}
查看看起来像下面的图片
请参阅下面的链接http://stackoverflow.com/questions/36587126/autolayout-ignores-multi-line-detailtextlabel-when-calculating-uitableviewcell-h –