Hey guys, I want to create a expandable Cell in my tableView but there are a few things which don't work. This is my Code:
// In TableView Cell
In TableView:
The first and biggest problem is that the cell height in the tableView doesn't fit to the height it should have after the cell expands. How can I do that?
The second problem is that the shrink functions doesn't work.
I hope someone can help me, thanks in advance!
// In TableView Cell
Code Block var bottomViewIsVisible = false func setUpArrowButton() { arrowButton.tintColor = .lightGray arrowButton.setImage(downImage, for: .normal) if bottomViewIsVisible == false { arrowButton.addTarget(self, action: #selector(expandView), for: .touchUpInside) } if bottomViewIsVisible == true { arrowButton.addTarget(self, action: #selector(self.shrinkView), for: .touchUpInside) } //Constraints arrowButton.translatesAutoresizingMaskIntoConstraints = false arrowButton.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true arrowButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -15).isActive = true arrowButton.widthAnchor.constraint(equalToConstant: 40).isActive = true arrowButton.heightAnchor.constraint(equalToConstant: 40).isActive = true } @objc func expandView() { bottomViewIsVisible = true UIButton.animate(withDuration: 0.3) { self.bottomView.isHidden = false self.arrowButton.setImage(self.upImage, for: .normal) } } @objc func shrinkView() { bottomViewIsVisible = false UIButton.animate(withDuration: 0.3) { self.bottomView.isHidden = true self.arrowButton.setImage(self.downImage, for: .normal) } } func setUpBottomView() { bottomView.backgroundColor = .systemPink bottomView.translatesAutoresizingMaskIntoConstraints = false bottomView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true bottomView.topAnchor.constraint(equalTo: Label.bottomAnchor, constant: 5).isActive = true bottomView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 10).isActive = true bottomView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -10).isActive = true bottomView.heightAnchor.constraint(equalToConstant: 60).isActive = true }
In TableView:
Code Block func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 2 { let priceSliderCell = tableView.dequeueReusableCell(withIdentifier: "PriceSlider", for: indexPath) as! PriceRangeCell priceSliderCell.setUpTitleLabel(text: "Price") priceSliderCell.setUpArrowButton() priceSliderCell.setUpBottomView() tableView.beginUpdates() tableView.endUpdates() tableView.deselectRow(at: indexPath, animated: true) priceSliderCell.delegate = self priceSliderCell.selectionStyle = .none return priceSliderCell } }
The first and biggest problem is that the cell height in the tableView doesn't fit to the height it should have after the cell expands. How can I do that?
The second problem is that the shrink functions doesn't work.
I hope someone can help me, thanks in advance!