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.

有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top