3

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.

Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129
edhnb
  • 2,122
  • 3
  • 24
  • 38

2 Answers2

6

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).

malex
  • 9,874
  • 3
  • 56
  • 77
0

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.

Oscar Gomez
  • 18,436
  • 13
  • 85
  • 118
  • The thing is that I need it to execute every time the view appears. So if the app comes back from sleeping, and is on that view.. it needs to execute. And any time the view is navigated too. I had thought that 'viewwillappear' would get foired when the view came back from sleeping.. but it does not. I think setting that flag would limit my calls to this logic to only once per launch... or am i missing something? Thanks. – edhnb Feb 05 '12 at 16:45