【发布时间】:2017-08-09 12:17:59
【问题描述】:
我将使用动态数量的单元格并在此基础上调整表格的高度。我可以通过我似乎无法调整表格大小来自己解决这个问题。无论我使用 100 个单元格还是 10 个单元格,视图都设置在相同的高度。
class generalTableViewController: UITableViewController {
override func viewWillAppear(_ animated: Bool) {
tableView.rowHeight = UITableViewAutomaticDimension
// self.tableView.contentSize.height = 2000
// self.tableView.frame.size.height = 2000
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1000
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
return cell
}
}
【问题讨论】:
-
使用-:tableView的heightForRowAtIndexPath方法
-
您是否要设置
UITableViewCell高度?还是UITableView高度? -
我可以调整 UITableViewCell,这是我遇到问题的 UITableView。
标签: ios swift uitableview height