I'm new to iPhone development. I've the following problem. This method (in viewcontroller 2) is triggered by an NSTimer event. Every few seconds a new "wheel" is produced and stored in the inventory. It works fine. However, after pushed the "back" button (to view controller 1) in the navigation bar and move again to view controller 2 the UIlabel text (self.wheelInStockSupplier.text) stops updating. The NSLog is working fine. What do i do wrong?
//update number of wheels in stock
self.numberOfWheelsInStockSupplier = self.numberOfWheelsInStockSupplier+1;
//Save inventory to user defaults
NSUserDefaults *wheelInventorySaver = [NSUserDefaults standardUserDefaults];
[wheelInventorySaver setInteger:self.numberOfWheelsInStockSupplier forKey:@"inventoryWheelsSupplier"];
//syngronize
[wheelInventorySaver synchronize];
self.wheelInStockSupplier.text = [NSString stringWithFormat:@"%i",self.numberOfWheelsInStockSupplier];
NSLog(@"%i",self.numberOfWheelsInStockSupplier);
Thanks for your help!
After many years I still remember the issue, and now I know the answer. It is not updating because it was not running on the UI thread. It should be something like: DispatchQueue.main.async { self.updateLabel() }