0

The func yesBtSetTextTo prints not nil when called from the grey button in the pink area, but the same func print nil when is called from the yellow button. I am lost on this one.

My main veiwController.swift does not have a prepareForSegue since I did not thing it is needed here.

enter image description here

The func in question is at the end of this code block,

MainBtVC.swift

protocol MainBtDelegate {
func yesBtSetTextTo(name: String)
}
class MainBtVC: UIViewController, MainBtDelegate {

@IBOutlet weak var yesBt: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

func yesBtSetTextTo(name: String) {
    print("called")
    if yesBt == nil {
        print("button is nil")
    } else {
        print("button not nil")
    }
    //      yesBt.setTitle("Exit", forState: UIControlState.Normal)
}

@IBAction func yesBtTapped(sender: AnyObject) {
    yesBtSetTextTo("dummy")
}

TopVC.swift

class TopVC: UIViewController {
var delegate: MainBtDelegate?

override func viewDidLoad() {
    super.viewDidLoad()
    delegate = MainBtVC()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

@IBAction func buttonTapped(sender: AnyObject) {
    delegate?.yesBtSetTextTo("Exit")
}
Fred J.
  • 5,759
  • 10
  • 57
  • 106

0 Answers0