Быстрое расширение ячейки Tableview, как отрегулировать высоту - PullRequest
0 голосов
/ 30 апреля 2018

надеюсь, что кто-нибудь может мне помочь, спасибо, в любом случае. Итак, понял расширяющуюся ячейку Tableview (когда я нажимаю на ячейку, она открывается более подробно), и теперь я хочу отрегулировать высоту ячейки, как мне это сделать? потому что перед ячейкой я хочу поместить изображение с описанием, и я хочу, чтобы ячейка находилась не сверху, а в конце моего контроллера, я попытался поместить воображение в свой контроллер представления, но у меня есть ошибка в моем коде, что код мне нужно для регулировки высоты и поместить изображение с описанием перед ячейкой?

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)

            }
        }

        }

    }

Ответы [ 2 ]

0 голосов
/ 30 апреля 2018

Я не уверен, правильно ли вас понял вопрос:

У вашей ячейки есть imageView с UILabel рядом с динамическим содержимым.

Вы можете использовать следующую логику.

Шаг: - 1 Убедитесь, что размер строки изменяется в обоих местах, как показано на снимках экрана:

enter image description here enter image description here

Шаг: - 2 Перетащите imageView и label в ячейку и выполните это со следующими ограничениями:

enter image description here

Надеюсь, это поможет.

0 голосов
/ 30 апреля 2018

Установите верхнюю, нижнюю, начальную и конечную метки, также установите количество строк на 0 . Установите высоту просмотра таблицы на UITableViewAutomaticDimension . Это позволит метке и ячейке расти в соответствии с содержимым.

ScreenShot 1

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...