0

I have one view controller and a calculator class. I have an instance of the calculator in the view controller and call a data fetching method through the instance. This also updates variables of the calculator instance. I would like to update a UILabel after the data fetch is complete but when I include

nameOFLabel.text = String(calculatorInstance.updatedValue)

as a completion handler of the data fetching method the label does not update when run even know the value changes.

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
badtrader
  • 1
  • 1
  • 1

1 Answers1

1

UI elements must be updated on the main execution thread. You can use the GDC (Grand Central Dispatch) routines to accomplish that. So try this:

dispatch_async(dispatch_get_main_queue(), {
    nameOFLabel.text = String(calculatorInstance.updatedValue)
})
zisoft
  • 22,770
  • 10
  • 62
  • 73