Search code examples
objective-ciosnsnotificationcenter

What happens when a nsnotification is sent to an inactive viewcontroller?


In my applicationWillEnterForeground, I check and send a notification if data refresh is necessary:

[[NSNotificationCenter defaultCenter] postNotificationName:@"refreshModelNotification" object:nil];

The only observer for that particular notification is a particular view controller:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshData:) name:@"refreshModelNotification" object:nil];

That view controller is one of several inside a UITabBarController.

My question is: what happens if that view controller isn't the active tab when the notification is sent?

Thanks in advance.


Solution

  • If the observer is still set for the view controller the view controller will still receive the notification and behave normally except any visual changes to the view controller's view will not be seen