Donal Rafferty
Donal Rafferty

Reputation: 19826

How to communicate with UI views from app delegate?

I am currently using the AppDelegate in my first iPhone app to handle application level events.

In my app I have an enabled and disabled state, so when the user selects disabled some of the buttons on the application should be set to disabled.

My AppDelegate gets notified of the state. But what is the best approach to let my UIViews know that they should disable some of their buttons?

What is the standard approach to communicate events from the AppDelegate to the UI screens?

EDIT:

My description is slightly wrong, the user can disable the buttons in my app but conditions such as lack of Wi-Fi can as well, so I need to be dynamically able to change the UI state also.

Upvotes: 1

Views: 421

Answers (2)

Manoj
Manoj

Reputation: 1003

I would say AppDelegate is always not the best approach. In my apps, rather I prefer Singleton class, they are quite easy to use. eg Singleton approach:

AppConfig* config = [AppConfig sharedInstance]; // AppConfig is my singleton instance
[[self usernameTextField] setText:[config studentName]];
[toggle setOn:[config alwaysShow]]; // toggle is UISwitch

hope this helps.

Upvotes: 1

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31722

Use NSNotification class to notify to your views.

Communicate using NSNotification

Communicate using NSNotificationCenter

Upvotes: 1

Related Questions