Search code examples
iosobjective-cnsnotification

Is there a simple way to let another ViewController know that a button has been pressed?


I have an app that requires that a menu changes in view controller 1 when a button in view controller 2 is pressed. What is the best way to achieve this?

I've heard a lot of talk about NSNotification but I thought that was for displaying alerts?


Solution

  • The "right" way to do this is to write the new state into the app's data model. When another view controller becomes active, it should update its view according to what the model says. That way, the information will be available to other view controllers even if they don't exist when the user makes the change.

    Notifications are a great way to convey information to other objects without having to know about them specifically, but a notification is only effective if the objects that care about it exist at the time that it's sent.