title: Protocol delegate not working within custom UIView button
body: <p>I have been trying to create a protocol and delegate within my custom UIView subclass, but when I call it on View Controller class the button is not responding to the method. I have read almost all the answers on StackOverflow, none of them solve my issue. Here is the procedure I have followed: </p>
  
  <h3>UIView Subclass <strong>(View A)</strong></h3>
  
  <p><strong>Create the require delegate:</strong></p>
  
  <pre><code>protocol LoginDelegates {
      func loginButtonPressed(sender: AnyObject)
  }
  </code></pre>
  
  <p><strong>Within Subclass</strong></p>
  
  <pre><code>class LoginViewController: UIViewController {
  
      @IBOutlet weak var loginButton: UIButton!
  
      var delegate: LoginDelegates? // Initite the delegate variable
  
      //Login Button Action
      @IBAction func loginButtonPressed(_ sender: UIButton) {
         delegate?.loginButtonPressed(sender: loginButton)
      }
  }
  </code></pre>
  
  <h3>View Controller Class (View B)</h3>
  
  <p>Call the delegate within the class: </p>
  
  <pre><code>class AccessViewController: UIViewController, LoginDelegates
  </code></pre>
  
  <p>In here I tried multiple approaches I have found on SO and around web. but none of them seems to work for me, the button still doesn't respond.</p>
  
  <p><strong>Approach 1:</strong> </p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
      //Assign the delegate in current view
      let LoginView = LoginViewController()
      LoginView.delegate = self
  }
  </code></pre>
  
  <p><strong><a href="https://stackoverflow.com/a/45815276/2556515">Approach 2</a>:</strong> 
  with this approach, I get the following error  <code>doesn't contain a view controller with identifier 'LoginViewController'</code>, which make sense cause the view is subclass and not within the storyboard.</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
      //Assign the delegate in current view
      if let loginView = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as? LoginViewController {
          loginView.delegate = self
      }
  
  }
  </code></pre>
  
  <p>and of course, call the method in the current view.</p>
  
  <pre><code>func loginButtonPressed(sender: AnyObject) {
       performSegue(withIdentifier: "toDashboard", sender: self)
  }
  </code></pre>
  
  <p>I also try to create a swift file and just put all the protocols separate from both views and just call them when needed. and At this point, I have no other option. Thank you for help in advance.</p>