viewWillAppear and UIApplicationDidBecomeActiveNotification

1.4k views Asked by At

I am using the UIApplicationDidBecomeActiveNotification to refresh my tableview when the app becomes active. My problem is that in my ViewWillAppear, I am also calling a method to refresh this table's data.

This is causing the table to be refreshed twice upon application launch. How can I get one of them not to fire when the app is initially launched? Refreshing the table has some intensive processing of network and local data.. so I would really like o only perform this action once.

Thanks.

2

There are 2 answers

1
Oscar Gomez On BEST ANSWER

One way to do it would be with a flag, that you can set up in didFinishLaunching, since that is only executed once per launch.

0
malex On

You need to use UIApplicationWillEnterForegroundNotification instead of UIApplicationDidBecomeActiveNotification.

The latter is posted every time your app becomes active (initial launch, back to app after call/sms interruption, etc.). But the former is posted only in case of wake up from background. Note that in this case viewWillAppear is not called (as it should seems to be at the first sight).