Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set UIView delegate?

I have an UIViewController

class WelcomeViewController: UIViewController

and an UIView

class SignUpView: UIView

Now I want to set in my WelcomeViewController delegate of SignUpView:

protocol SegueDelegate {
    func runSegue(identifier: String)
}

class SignUpView: UIView { ... }

and connect it in

class WelcomeViewController: UIViewController, SegueDelegate {

how can I set in my WelcomeViiewController those delegate? When I'm trying to set:

override func viewDidLoad() {
    SignUpView.delegate = self
}

it returns me

Instance member 'delegate' cannot be used on type 'SignUpView'

how can I find a solution?

like image 743
John Doe Avatar asked Mar 03 '16 09:03

John Doe


People also ask

What are delegates in iOS?

What is delegate methods in iOS? It is an easy and influential pattern in which one object in a program works on behalf of or in coordination with, another object. The delegating object keeps a reference to the other object and at the suitable time sends a message to it.

What is a UIViewController?

The UIViewController class defines the methods and properties for managing your views, handling events, transitioning from one view controller to another, and coordinating with other parts of your app.


1 Answers

You are trying to set delegate to a class. It should be an instance of the class i.e

let signUpView = SignUpView()
signUpView.delegate = self
like image 71
Yunus Eren Güzel Avatar answered Oct 09 '22 06:10

Yunus Eren Güzel