我已经看了几个教程,展示了如何设置动态单元格高度,但是如果你通过设置适当的约束和使用动态单元格,它们都只显示它UITableViewAutomaticDimension.但是,我想对静态细胞这样做.
我的应用程序中有一个表视图控制器,其中包含几个单元格,这些单元格显示带有公开指示符的类别,其中有标题,然后是描述,描述文本的大小各不相同.因此,我希望单元格的高度根据描述文本的大小是动态的.
我使用静态单元而不是动态单元的原因是因为在类别单元格之上我有一些具有一些设计的单元格,我只能通过使用静态单元格和故事板来获得.
我正在使用iOS9,Xcode 7.3和Swift 2.2
UPDATE
表视图控制器代码
import UIKit
class CategoriesTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 140
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: …Run Code Online (Sandbox Code Playgroud)