skip to Main Content

The code below is where I set the constraints of the UITableViewCell.

private func configureConstraints() {
        let agentIconImageViewConstraints = [
            agentIconImageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 10),
            agentIconImageView.topAnchor.constraint(equalTo: contentView.topAnchor,constant: 20),
            agentIconImageView.widthAnchor.constraint(equalToConstant: 64),
            agentIconImageView.heightAnchor.constraint(equalToConstant: 32)
        ]
        
        let flightTimeAndAirportsStackViewConstraints = [
            flightTimeAndAirportsStackView.leadingAnchor.constraint(equalTo: agentIconImageView.trailingAnchor, constant: 10),
            flightTimeAndAirportsStackView.topAnchor.constraint(equalTo: agentIconImageView.topAnchor, constant: -5),
            flightTimeAndAirportsStackView.bottomAnchor.constraint(equalTo: agentIconImageView.bottomAnchor)
        ]
        
        let flightStopsAndTimeDurationStackViewConstraints = [
            flightStopsAndTimeDurationStackView.topAnchor.constraint(equalTo: flightTimeAndAirportsStackView.topAnchor),
            flightStopsAndTimeDurationStackView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20),
            flightStopsAndTimeDurationStackView.bottomAnchor.constraint(equalTo: flightTimeAndAirportsStackView.bottomAnchor)
        ]
        
       
        
        NSLayoutConstraint.activate(agentIconImageViewConstraints)
        NSLayoutConstraint.activate(flightTimeAndAirportsStackViewConstraints)
        NSLayoutConstraint.activate(flightStopsAndTimeDurationStackViewConstraints)



   }

However, as can be seen in the image, it extends beyond the cell. Are there any constraints I forgot to set? otherwise why is this happening

enter image description here

2

Answers


  1. It looks like you are setting constraints for several UI elements (agentIconImageView, flightTimeAndAirportsStackView, flightStopsAndTimeDurationStackView) within a UITableViewCell. It appears that some of the constraints may be causing the elements to appear outside of the cell.

    One potential issue is the negative constant value being used on the topAnchor of the flightTimeAndAirportsStackView (constant: -5). This could be causing the stack view to be positioned above the agentIconImageView. Additionally, the bottomAnchor of flightStopsAndTimeDurationStackView is constrained to flightTimeAndAirportsStackView.bottomAnchor, this could cause both stack views to be positioned outside the cell.

    You might want to check and adjust the constant values, and also check if the components are going outside of the cell.

    Login or Signup to reply.
  2. You haven’t given any constraint to the bottom of the contentview. The content view can not infer the height automatically. Either give a calculated height for the cell from your tableview delegate, or give some item a bottom constraint to contentview.bottomAnchor.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search