简体   繁体   English

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

[英]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. 这将使标签和细胞根据内容而增长。

屏幕截图1

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: 步骤:-2imageViewlabel拖动到单元格中,并按照以下约束完成操作:

在此处输入图片说明

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在swift中调整tableview标题的高度? - How to adjust the height of the header of a tableview in swift? 根据内容动态调整tableview单元格的高度 - iOS Swift - Dynamically adjust the height of the tableview cell based on content - iOS Swift 如何在自定义tableView单元格中调整标签的高度和宽度 - How to adjust label height and width in custom tableView Cell 表格视图单元格内的表格视图自动调整单元格高度 - tableview inside tableview cell adjust cell height automatically TableView单元格内的TableView,自动调整单元格高度 - TableView inside TableView cell, adjust cell height automatically Swift TableView单元格比例高度 - Swift tableview cell proportional height 在iOS目标c中,顶部展开折叠自定义单元格tableview和单元格如何必须是动态高度 - How top expand collapse custom cell tableview and expanding the cell must be dynamic height in iOS objective c 如何在Swift iOS中调整集合视图单元格的高度? - How to adjust collection view cell height in swift ios? 从自定义tableview单元格类加载时,如何调整单元格的高度? - how to adjust the height of a cell when loading from the custom tableview cell classes? 根据SWIFT中子视图的高度调整scrollview的高度 - Adjust the height of scrollview according to the height of his child tableview in SWIFT
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM