ios - 单元格尺寸 rowHeight 大小
问题描述
我需要调整我的UITableViewCell
尺寸。我通过更改 rowHeight.dimension 来做到这一点,但它不起作用。
class SobreViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight=150
}
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 9
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell();
switch indexPath.row{
case 1:
guard let cell = tableView.dequeueReusableCell(withIdentifier: "s1") else {return UITableViewCell()}
cell.textLabel?.text = "A aplicação móvel MyInfo@IPLeiria permite-te consultar de forma simples e rápida alguma da tua informação académica, quer lista de unidades curriculares a que estás inscrito no teu ano letivo atual, quer a data/hora das tuas avaliações, quer o teu horário, as tuas notas ou até mesmo a referência para o pagamento das propinas."
return cell;
case 2:
guard let cell = tableView.dequeueReusableCell(withIdentifier: "s2") else {return UITableViewCell()}
cell.textLabel?.text = "MyInfo@IPLeiria foi desenvolvida no âmbito de projeto final de Licenciatura de Engenharia Informática"
return cell;
case 3:
guard let cell = tableView.dequeueReusableCell(withIdentifier: "versaoAplicacao") else {return UITableViewCell()}
cell.detailTextLabel?.text = "1.0"
return cell;
case 4:
guard let cell = tableView.dequeueReusableCell(withIdentifier: "s4") else {return UITableViewCell()}
cell.textLabel?.text = "Tecnologia"
return cell;
case 5:
guard let cell = tableView.dequeueReusableCell(withIdentifier: "versaoFramework") else {return UITableViewCell()}
cell.detailTextLabel?.text = "1.0.0"
return cell;
case 6:
guard let cell = tableView.dequeueReusableCell(withIdentifier: "versaoNode") else {return UITableViewCell()}
cell.detailTextLabel?.text = "5.12.0"
return cell;
case 7:
guard let cell = tableView.dequeueReusableCell(withIdentifier: "versaoCordova") else {return UITableViewCell()}
cell.detailTextLabel?.text = "5.4.1"
return cell;
case 8:
guard let cell = tableView.dequeueReusableCell(withIdentifier: "s8") else {return UITableViewCell()}
cell.textLabel?.text = "Podes consultar toda a informação em modo online e em modo offline"
return cell;
case 9:
guard let cell = tableView.dequeueReusableCell(withIdentifier: "s9") else {return UITableViewCell()}
cell.textLabel?.text = "Copyright Politécnico de Leiria © 2019"
return cell;
default:
break;
}
return cell;
}
}
解决方案
你也需要实现 UITableViewDelegate 的这个功能:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
同样对于 UITableViewCell,您需要将标签设置为多行:
cell.textLabel?.numberOfLines = 0
cell.textLabel?.lineBreakMode = UILineBreakModeWordWrap
推荐阅读
- java - 为列表制作过滤器 - ANDROID
- python - 抓取与“tr class”标签关联的“p”标签值
- mysql - 按名称、月份、年份分组的 SQL 数字总和
- python - 谷歌可视化使用python查询数据到表
- javascript - 如何将总订单添加到 PayPal javascript 按钮
- javascript - 尝试将 TensorFlow 保存的模型转换为 TensorFlow.js 模型时出错
- javascript - 如何在 three.js 中的纹理上应用自定义 mipmap?
- go - 无法处理在 Windows (ImageSearch.dll) 上返回 char* 的自定义 dll
- laravel - Laravel Auth 使用自定义消息重置密码
- react-native - 如何在 android 的窗口管理器视图上启动 react-native