[英]Swift expanding Tableview cell how to adjust height
hope that somebody can help me, thank you already anyway. 希望有人可以帮助我,无论如何都谢谢你。 So realized an expanding Tableview cell (when i tap the cell it open with more detail) and now i want to adjust the height the cell, how i have to do? 如此实现了一个扩大的Tableview单元格(当我点击它以更详细的方式打开它时),现在我想调整该单元格的高度,我该怎么办? because before the cell i want to put an image with a description and i want the cell not on the top but at the end of my controller, i tried to put an imagine in my view controller but i have a error in my code, what code i need for adjust the height and put an image with description before the cell? 因为在单元格之前,我想放置一个带有描述的图像,并且希望该单元格不在控制器的顶部,而是在控制器的末尾,所以我试图在我的视图控制器中放置一个想象,但是我的代码中有错误,我需要调整高度的代码,并将带有说明的图像放在单元格之前?
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)
}
}
}
}
Set the top, bottom, leading, and trailing for the label, also set number of lines to 0 .set the tableview height to UITableViewAutomaticDimension . 设置标签的顶部,底部,前导和尾随,还将行数设置为0。将tableview的高度设置为UITableViewAutomaticDimension 。 This will make the label and cell grow according to the content. 这将使标签和细胞根据内容而增长。
I am not sure if understood you question Correctly: 我不确定是否理解您提出正确的问题:
Your cell has and imageView
with a UILabel
next to it with dynamic content. 您的单元格有imageView
带有UILabel
旁边是动态内容。
You can use the following logic. 您可以使用以下逻辑。
Step:- 1 Make sure the row size is changed at both the places as shown on Screen shots: 步骤:-1如屏幕截图所示,确保在两个地方都更改了行大小:
Step:- 2 Drag an imageView
and label
into cell and get it done with following constraints: 步骤:-2将imageView
和label
拖动到单元格中,并按照以下约束完成操作:
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.