0

All,

I have set up a protocol, and the view controller is the delegate of this protocol, like so :

import Foundation

protocol PayButtonProtocol {
    func enablePayButton()
    func disablePayButton()
}

And the view controller is the delegate :

class ViewController:   UIViewController, PayButtonProtocol

The protocol functions are as follows :

func enablePayButton() {
        println("Button enabled")
        PAYBarButton.enabled = false
    }

    func disablePayButton() {
        PAYBarButton.enabled = false
    }

I set a class and assign the delegate :

class Trigger
{
    var delegate:PayButtonProtocol?

    func EnablePayButton()
    {
        delegate?.enablePayButton()
    }
}

Then I set the trigger to run the function :

let localtrigger = Trigger()
        localtrigger.delegate = ViewController()
        localtrigger.EnablePayButton()

This works and the 'button enabled' is displayed in the console. But the Bar Button (PAYBarButton) is nil and it seems that the view controller has lost its hieracy as I cannot access any of the view controllers objects. The View Controller was built with interface builder. Anyone got any ideas ? Is it

localtrigger.delegate = ViewController()

that rebuilds the viewconotroller and makes the original one not accessible ? If so how do i do this ?

1 Answer 1

0

if you are creating the localTrigger object inside your ViewController class you can just do:

let localtrigger = Trigger()
localtrigger.delegate = self // self is an instance of ViewController
localtrigger.EnablePayButton()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.