1

In iOS 7.1 I set an integer variable in my viewDidAppear method. It works at first, but after navigating to another view controller and navigating back my integer variable is now set at zero. If I move integer variable setup to viewDidLoad it works every time.

In iOS 8 it works every time in the viewDidAppear method.

Why would this work in 8, but not 7.1?

mcphersonjr
  • 733
  • 12
  • 35
  • Have you done any debugging to see what is setting it to zero? – rmaddy Oct 08 '14 at 17:18
  • If this is a property, you can override the accessor and put a breakpoint in it to see when it's accessed by your code. Of course, that would mean you'd have to use the dot operator consistently in your code for this to be useful at all. – Hyperbole Oct 08 '14 at 17:19
  • Keep in mind that the precise order of invoking various UI delegate methods may vary between versions (and even in a single version, from case to case). Also, my understanding is that iOS 8 recreates views (ie, re-executing viewDidLoad) more often than in 7, so if your reference is not to a view that's currently being displayed then you shouldn't depend on initialization in viewDidAppear. – Hot Licks Oct 08 '14 at 17:30

1 Answers1

2

I can't speak to the question of the differences between iOS 7 and iOS 8 in regards to viewDidAppear, here are some what I hope are useful links to take a look at.

There was a question answered that addressed the call/event cycle that contains a graphic that you may find useful:

iOS 7 - Difference between viewDidLoad and viewDidAppear

And this link has a reference to a UIViewController using a UINavigationController that, in turns, manages other UIViewControllers and the viewDidAppear message was getting lost in the hierarchy. The fix was to ensure that the navigation controller explicitly called viewDidAppear so it would be passed it to the child views.

http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/

Not sure of your exact situation, but hopefully these will help.

Community
  • 1
  • 1
sunergeos
  • 321
  • 2
  • 4
  • This is a comment, not an answer. – rmaddy Oct 08 '14 at 18:15
  • Don't have the reputation points to comment above. Feel free to move it. – sunergeos Oct 08 '14 at 18:16
  • I've up voted your answer, which pushes you past the 50 rep needed to comment. In the future, a post like this should be done as a comment, not an answer. I'm letting it slide for two reasons: 1 - the question strikes me as low quality, basically asking for links to documentation. 2 - You didn't have enough rep to comment prior to my up vote. Now you do, so don't do it again. – ArtOfWarfare Oct 08 '14 at 22:47