我需要调整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;
}
}
答案 0 :(得分:1)
您还需要实现UITableViewDelegate的此功能:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
对于UITableViewCell,还需要将标签设置为多行:
cell.textLabel?.numberOfLines = 0
cell.textLabel?.lineBreakMode = UILineBreakModeWordWrap
答案 1 :(得分:0)
向您的代码添加以下内容:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}