gpt4 book ai didi

ios - 快速扩展Tableview单元格如何调整高度

转载 作者:行者123 更新时间:2023-11-28 07:49:28 25 4
gpt4 key购买 nike

希望有人能帮助我,无论如何已经谢谢你了。所以实现了一个扩展的 Tableview 单元格(当我点击单元格时它会打开更多细节)现在我想调整单元格的高度,我该怎么办?因为在单元格之前我想放一个带有描述的图像并且我希望单元格不在顶部而是在我的 Controller 的末尾,我试图在我的 View Controller 中放一个想象但是我的代码有错误,什么我需要调整高度并将带有描述的图像放在单元格之前的代码吗?

class PROVAViewController: UITableViewController {

var tableViewData = [cellData]()

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.

tableViewData = [cellData(opened: false, title: "Title1", sectionData: ["Cell1","Cell2","Cell3"]),
cellData(opened: false, title: "Title1", sectionData: ["Cell1","Cell2","Cell3"]),
cellData(opened: false, title: "Title1", sectionData: ["Cell1","Cell2","Cell3"]),
cellData(opened: false, title: "Title1", sectionData: ["Cell1","Cell2","Cell3"])]
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

override func numberOfSections(in tableView: UITableView) -> Int {
return tableViewData.count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableViewData[section].opened == true {
return tableViewData[section].sectionData.count + 1
} else {
return 1
}

}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let dataIndex = indexPath.row - 1
if indexPath.row == 0 {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") else {return UITableViewCell()}
cell.textLabel?.text = tableViewData[indexPath.section].title
return cell

} else {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") else {return UITableViewCell()}
cell.textLabel?.text = tableViewData[indexPath.section].sectionData[dataIndex]
return cell
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0 {
if tableViewData[indexPath.section].opened == true {
tableViewData[indexPath.section].opened = false
let sections = IndexSet.init(integer: indexPath.section)
tableView.reloadSections(sections, with: .none) // play around with it(cosa significa non lo so, vedi video)

}else{
tableViewData[indexPath.section].opened = true
let sections = IndexSet.init(integer: indexPath.section)
tableView.reloadSections(sections, with: .none)

}
}

}

}

最佳答案

设置标签的顶部、底部、前导和尾部,还将行数设置为0。将tableview高度设置为UITableViewAutomaticDimension .这将使标签和单元格根据内容增长。

ScreenShot 1

关于ios - 快速扩展Tableview单元格如何调整高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50092366/

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