Okay, no it does not crash, the bottom view is visible when I tap on the bottom but you can't really see him because the cell Height doesn't fit.
This is the implementation in the tableView:
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.selectionStyle = .none
return priceSliderCell
}
This is the code for the cell Height:
//Cellheight IndexPath 2
let heightOfBottomView = CGFloat(95)
let basicHeight = CGFloat(50)
lazy var fullHeight = heightOfBottomView + basicHeight
var visibleBottomView = false
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) - CGFloat {
//...
if indexPath.row == 2 {
return visibleBottomView ? fullHeight : basicHeight
}
And this is the cell class:
class PriceRangeCell: UITableViewCell {
let Label = UILabel()
let bottomView = UIView()
var bottomViewIsVisible = false
var delegate: ExpandProtocol?
let arrowButton = UIButton()
let arrowConf = UIImage.SymbolConfiguration(pointSize: 20)
lazy var downImage = UIImage(systemName: "chevron.down", withConfiguration: arrowConf)
lazy var upImage = UIImage(systemName: "chevron.up", withConfiguration: arrowConf)
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(Label)
contentView.addSubview(arrowButton)
contentView.addSubview(bottomView)
bottomView.isHidden = true
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setUpTitleLabel(text: String) {
Label.text = text
Label.textAlignment = .left
Label.font = UIFont.systemFont(ofSize: 17, weight: .medium)
Label.tintColor = .black
Label.translatesAutoresizingMaskIntoConstraints = false
Label.topAnchor.constraint(equalTo: topAnchor, constant: 10).isActive = true
Label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 15).isActive = true
Label.heightAnchor.constraint(equalToConstant: 30).isActive = true
Label.widthAnchor.constraint(equalToConstant: 160).isActive = true
}
func setUpArrowButton() {
arrowButton.tintColor = .lightGray
arrowButton.setImage(downImage, for: .normal)
arrowButton.addTarget(self, action: #selector(expandView), for: .touchUpInside)
arrowButton.translatesAutoresizingMaskIntoConstraints = false
arrowButton.topAnchor.constraint(equalTo: topAnchor, constant: 10).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() {
if bottomViewIsVisible != false {
UIButton.animate(withDuration: 0.3) {
self.bottomView.isHidden = true
self.arrowButton.setImage(self.downImage, for: .normal)
}
bottomViewIsVisible = false
} else {
UIButton.animate(withDuration: 0.3) {
self.bottomView.isHidden = false
self.arrowButton.setImage(self.upImage, for: .normal)
}
bottomViewIsVisible = true
}
}
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
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
I'm really thankful for your efforts!