0

I have view1 and view2. In view2 I set up a delegate and enter some data. When I press the save button i view2 I am sent to view1. In view1 I get the data I entered in view2. BUT... when I try to update a label or button text in view1 with the data from view2 nothing happens. View1 is not updated.

This is the delegate function in view1 which should update the label:

func getCurrentContact(ViewController: ViewControllerSettings, data: (ContactDetails)) {
    NSLog("Yes, the delegate is called")

    self.lblContact1.text = data.name1 as? String
}

Anyone know why lblContact1.text is not updated? It just stay the same as on startup. The NSLog of data.name1 contains the correct data I entered in view2. Seems like view1 needs to be refreshed or something...

BTW; Does anyone know about a working swift project in GitHub or something that has navigation controller and a working delegate for sending data from view2 to view1? Would be outstanding...

TommyF
  • 381
  • 1
  • 7
  • 22

1 Answers1

0

Try rewriting your code like this to have some more success debugging this:

func getCurrentContact(ViewController: ViewControllerSettings, data: (ContactDetails)) {
    println("Yes, the delegate is called")

    if let name = data.name1 as ? String {
        println("Setting lblContact1 with \(name)")
        self.lblContact1.text = name
    } else {
        println("Either data was empty or data.name1 couldn't be extracted")
    }
}

If you're actually receiving data.name1 as expected – then I would check that the the code you supplied is actually running on the main thread.

Note that I've also replaced NSLog with println for a number of reasons

Community
  • 1
  • 1
dangnabit
  • 654
  • 3
  • 9
  • Yes, println("Setting lblContact1 with \(name)") returns the correct data. But self.lblContact1.text is not updated. This is driving me nuts... – TommyF Aug 26 '15 at 07:56