gpt4 book ai didi

ios - 单元格维度 rowHeight 大小

转载 作者:行者123 更新时间:2023-11-28 13:40:39 24 4
gpt4 key购买 nike

我需要调整我的 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

关于ios - 单元格维度 rowHeight 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56076935/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com