Form sheet is not getting detected when being swiped down

Viewed 64

I have a parent view controller and a child view controller. I have a button that can show that child view controller. The button does these actions: self.performSegue(withIdentifier: "showComments", sender: self). I also have prepared the segue and set segue.destination.presentationController?.delegate = self. I have put UIAdaptivePresentationControllerDelegate into my view controller and tried putting this function:

public func presentationControllerDidDismiss(
        _ presentationController: UIPresentationController)
      {
        print("dismissed")
      }

When I try to drag down the form sheet it doesn't print anything telling me that something is wrong here. Is there a reason to why this is happening?

Edit: Here is my view controller:


import UIKit

class ViewController: UIViewController, UIAdaptivePresentationControllerDelegate {
    func presentationControllerWillDismiss(_: UIPresentationController) {
        print("yep2")
        viewWillAppear(true)
    }
    @IBOutlet weak var commentImage: UIImageView!
    override func viewDidLoad() {
        super.viewDidLoad()
        let vc = CommentingViewController()
        vc.presentationController?.delegate = self
        let tappp = UITapGestureRecognizer(target: self, action:#selector(ChannelVideoViewController.tapppFunction))
        commentImage.addGestureRecognizer(tappp)
        // Do any additional setup after loading the view.
    }
    override func prepare(for segue: UIStoryboardSegue, sender: Any?)
    {
            if segue.destination is CommentingViewController {
                if segue.identifier == "showComments" {
                    segue.destination.presentationController?.delegate = self
                }
            }
    }
    var isDismissed: Bool = true
    @objc func tapppFunction(sender:UITapGestureRecognizer) {
        isDismissed = true
        self.performSegue(withIdentifier: "showComments", sender: self)
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(true)
        isDismissed = true
        print("View Disappeared")
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
        isDismissed = false
        print("view appeared")
    }
}

Edit 2: I'm not sure if this helps but I also have my child view controller in another storyboard.

2 Answers

Your issue is occurring probably because of the delegate is not getting set. Modify the prepare(for:,sender:) method to the following:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let destination = segue.destination as? CommentingViewController {
        destination.presentationController?.delegate = self
    } else {
        print("Not CommentingViewController")
        segue.destination.presentationController?.delegate = self
    }
}

In my original question I actually put a modified version of my view controller as it was pretty big and messy with other things. After looking at my prepare(for:,sender:) I realized that I was checking for the wrong view controller (Frakenstein kind of helped me find it). Here is what I'm talking about:

override func prepare(for segue: UIStoryboardSegue, sender: Any?)
    {
        if segue.destination is OtherViewController
        {
            if let vc = segue.destination as? OtherViewController {
                if segue.identifier == "showOther" {
                    vc.other = self.other
                }
            } else if segue.destination is CommentingViewController {
                if segue.identifier == "showComments" {
                    segue.destination.presentationController?.delegate = self
                }
            }
        }
    }

So it wasn't working too well. But it does work through storyboard references.

Related