Post

Replies

Boosts

Views

Activity

Reply to How to set up a expandable TableView Cell?
Do you mean like this: let heightOfBottomView = CGFloat(60)     let basicHeight = CGFloat(50)     lazy var fullHeight = heightOfBottomView + basicHeight          var visibleBottomViews : [Bool] = [] func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) - CGFloat {         if indexPath.row == 0 {             //SegmentControl Rent of Buy             return 60         }         if indexPath.row == 1 {             //Segment Control Property Types             return 60         }         if indexPath.row == 2 {             //Price Slider             return visibleBottomViews[indexPath.row] ? fullHeight : basicHeight         }         if indexPath.row == 3 {             //Size Slider             return 118 }         } This throws me the following error: Thread 1: Fatal error: Index out of range
Apr ’21
Reply to How to set up a expandable TableView Cell?
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!
Apr ’21
Reply to Push data to other VC with protocol, error: force unwrapped a nil value
VC1: class NameVC: UIViewController, RegisterNameProtocol {     var name: String?     let vc3 = VerifyPhoneNumberVC()  override func viewDidLoad() {         super.viewDidLoad()         view.backgroundColor = .black         vc3.nameDelegate = self } @objc func goNext() { The function which presents vc2          name = nametextField.text!         print("Name: \(vc3.Username)") ... } } VC2: class PhoneNumberVC: UIViewController, UITextFieldDelegate, RegisterNumberProtocol {     var phoneNumber: String?     let vc3 = VerifyPhoneNumberVC() override func viewDidLoad() {         super.viewDidLoad()         view.backgroundColor = .black         vc3.phoneDelegate = self ... } func push() {         phoneNumber = phoneNumberTextField.text!         print("Number: \(phoneNumber)") ... } } V3: class VerifyPhoneNumberVC: UIViewController { var nameDelegate: RegisterNameProtocol?     var phoneDelegate: RegisterNumberProtocol?     var UserphoneNumber = ""     var Username = "" override func viewDidLoad() {         super.viewDidLoad()         view.backgroundColor = .white         UserphoneNumber = (phoneDelegate?.phoneNumber) ?? ""         Username = (nameDelegate?.name) ?? ""         print("Number: \(UserphoneNumber), Name: \(Username)") } I think that's all:)
May ’21
Reply to Push data to other VC with protocol, error: force unwrapped a nil value
Of course, I thought it would be unnecessary, here I the code:  @objc func goNext() {          name = nametextField.text!         print("Name: \(name)")                  if nametextField.text?.isEmpty == false {             let nextVC = PhoneNumberVC()             nextVC.modalPresentationStyle = .fullScreen             present(nextVC, animated: true, completion: nil)         } else {             print("No valid name")         }     }
May ’21