PopupDialogCustomExample icon indicating copy to clipboard operation
PopupDialogCustomExample copied to clipboard

View Controller Doesn't Appear

Open p3scobar opened this issue 7 years ago • 3 comments

A view controller doesn't appear when the popup is presented with the following code - just a blur view. What am I missing here?

View Controller A:


    func showPopup() {
        let vc = ViewControllerB()
        let popup = PopupDialog(viewController: vc)
        vc.popup = popup
        self.present(popup, animated: true, completion: nil)
    }

View Controller B:

class ViewControllerB: UIViewController {

    var popup: PopupDialog?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupView()
    }


    lazy var card: UIView = {
        let view = UIView()
        view.backgroundColor = .white
        view.translatesAutoresizingMaskIntoConstraints = false
        return view
    }()

    func setupView() {
       view.addSubview(card)
        
        card.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
        card.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
        card.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
        card.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
    }
}

p3scobar avatar Jan 10 '18 19:01 p3scobar

Hey there! As you don't have any elements inside your view, the height ends up being 0. If you want to test an empty view, you would have to set a specific height constraint. Make sure to have a seamless chain of constraints from top to bottom, once you add elements. This way, the dialog height will adapt to the height of the elements inside the view.

By the way, make sure to have a weak reference to PopupDialog in your view controller, otherwise it will never be deallocated.

weak var popup: PopupDialog?

mwfire avatar Jan 11 '18 00:01 mwfire

Adding this to the CustomViewController made it show up for me:

override func viewDidLoad() {
  super.viewDidLoad()
  // Setup constraints
  self.view.heightAnchor.constraint(equalToConstant: 220).isActive = true
}

davidkneely avatar Jul 31 '20 04:07 davidkneely

A seamless chain of constraints from top to bottom! Thank god!

Fando avatar Jan 07 '21 07:01 Fando