1

I have added a protocol that makes a segue from a UIView button to a NavigationController but when i compile and press the button after the UIView opens it just does nothing which seems pretty weird since it all makes sense to me at least, Please if I am doing anything wrong lead me to fix my code.

I got this code from this Answer: https://stackoverflow.com/a/52789290/18277261

Code:

 class popUpView: UIView, UITextFieldDelegate {

 @IBOutlet weak var popUpViewInterface: UIView!
 @IBOutlet weak var payNowPopUp: UIButton!

 let delegate: popUpViewDelegate? = nil

 @IBAction func payNowToWebView(_ sender: Any) {
    
    let myColor = UIColor.red
    
    priceTextFieldPopUp.layer.borderColor = myColor.cgColor
    priceTextFieldPopUp.layer.borderWidth = 1.0
    
    self.delegate?.performSegueFromView(withIdentifier: "paymentWebView")
   }
}

 protocol popUpViewDelegate {

    func performSegueFromView(withIdentifier identifier: String)
}

 class dashboardViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, UICollectionViewDataSource, ChartViewDelegate, AxisValueFormatter, popUpViewDelegate {

 func performSegueFromView(withIdentifier identifier: String) {

    self.performSegue(withIdentifier: identifier, sender: nil)
} 
  • 1
    Just a side note. It’s very hard to read code if you don’t follow conventions like type names should begin with uppercase letters. For instance `class DashboardViewController` should begin with `D` same for protocols and structs. – Fogmeister May 15 '22 at 23:03
  • 1
    @Fogmeister Got it! , Thanks a lot for this note I didn't know that and will surely do that for Type Names, Structs, Protocols ! – Lis Tahirbegolli May 15 '22 at 23:17

1 Answers1

0

In dashboardViewController where you initialise popUpView make sure that you set the delegate like below.

let popView = popUpView()
popView.delegate = self
MBT
  • 1,381
  • 1
  • 6
  • 10