我正在爲列表製作一個視圖。它具有動態的字幕長度。所以我使用了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 –