开发者

How to communicate with UI views from app delegate?

开发者 https://www.devze.com 2023-03-15 12:37 出处:网络
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 o

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 applicati开发者_开发问答on 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.


Use NSNotification class to notify to your views.

Communicate using NSNotification

Communicate using NSNotificationCenter


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消