0
votes
class PopPop: UIViewController {
    var quickVouch = UIView()

    @IBAction func closePopPop (sender: UIButton) {
        self.view.removeFromSuperview()
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor.black.withAlphaComponent(0.2)

        quickVouch.frame = CGRect.init(x: 0, y: 0, width: 260, height: 300)
        quickVouch.backgroundColor = UIColor.black
        quickVouch.center = self.view.center
        quickVouch.layer.cornerRadius = 0
        quickVouch.layer.shadowOpacity = 0.0
        quickVouch.layer.shadowOffset = CGSize(width: 0.0, height: 0.0)
        self.view.addSubview(quickVouch)

        let btn: UIButton = UIButton(frame: CGRect(x: 100, y: 265, width: 60, height: 30))
        btn.backgroundColor = UIColor.black
        btn.setTitle("Close", for: .normal)
        btn.addTarget(self, action: Selector(("buttonAction:")), for: UIControlEvents.touchUpInside)
        btn.setTitleColor(UIColor.lightGray, for: .normal )
        btn.titleLabel!.font = UIFont(name: "AvenirNextCondensed-Medium", size: 20)!
        quickVouch.addSubview(btn)
    }

Not sure why I'm getting this error. When button is pressed the App Crashes. Pretty new to code and possibly missing something here....

func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {

    let PopOverViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PopPopID") as! PopPop
    self.addChildViewController(PopOverViewController)
    PopOverViewController.view.frame = CGRect(x: 0, y: -70, width: 1000, height: 1000)
    self.view.addSubview(PopOverViewController.view)
    PopOverViewController.didMove(toParentViewController: self)


}

This is the code from the main ViewController.

1
What's the name of the selector that is not recognized? - almas
It's saying PopPop button action. - JammyBugger
Do you have a method called 'PopPop' somewhere in your code? Did you rename 'PopPop' to 'closePopPop' and didn't rewire the outlet in your nib? - almas

1 Answers

0
votes

I changed this line of code and now everything works as planned!

btn.addTarget(self, action: #selector(PopPop.buttonAction(_:)), for: UIControlEvents.touchUpInside)