1

How many times viewWillAppear method gets called in the lifetime of a view controller?

I wanted to register for a notification only once when that view is loaded in memory and deregister it once it is unloaded.

When I do it viewDidLoad method my view gets register multiple times.

Abhinav
  • 37,684
  • 43
  • 191
  • 309

2 Answers2

2

Wht you are asking for is exactly what -viewDidLoad and -viewDidUnload provide. A UIViewController may load and unload it's view many times during the view controller's life (view controllers unload their views in response to memory warnings if the view is not visible). You should be able to register for notifications every time the view is loaded as long as you unregister when the view is unloaded.

Jonah
  • 17,918
  • 1
  • 43
  • 70
0

You could try using awakeFromNib if you're using a xib file.

Hobbes the Tige
  • 3,753
  • 2
  • 22
  • 21