Reputation: 279
If I'm using NSNotifications
to tell my UITableViews
(in different Controllers) to add a new Cell, but the Controller in which that UITableView
lies has not been "accessed" yet or loaded/init'd, that Controller will not receive the message (as my NSNotificationCenter
is setup in each of my viewDidLoad
). This is the expected behavior as I understand.
Now my question: Is there a way to have the Controller's that haven't been accessed yet once the app launches receive the notification? Or is there a better approach of posting to another UIViewController
's UITableView
from a different UIView
rather than using NSNotifications
?
I saw a similar question asked a few years back, so if anyone can chime in, would be greatly appreciated!
Upvotes: 0
Views: 65
Reputation: 1340
If you want your controller to receive a notification before it's accessed (i.e. its view is loaded and viewDidLoad
is called) then you need to subscribe for a notification in one of the init
methods:
If you want to create your controller programmatically then you need to do it in init
or initWithStyle:
methods.
If you want to create your controller programmatically from .xib
file then you need to do it in initWithNibName:bundle:
method.
If you want to create your controller from .storyboard
file then you need to do it in initWithCoder:
method.
Upvotes: 1