1

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.

2 Answers 2

1

Use NSNotification class to notify to your views.

Communicate using NSNotification

Communicate using NSNotificationCenter

Sign up to request clarification or add additional context in comments.

5 Comments

Doesn't appear to work too well, I've already encountered loads of issues from the observer taking too long to set up and missing the notifications to the screen failing to redraw when it gets a notification.
@Donal Rafferty : I has been using it at more than 50 places in my project,i find it very easy and lite way for sending redraw event to UI.
But if the UIView is not in focus does it still receive the notification?
@Donal Rafferty:Yes, you need to take care for these cases as well, you could remove the notification when it's not focused and add again when it;s focused.
This means that my screens may show incorrect data, I need to be able to let all screens know that they should be in a specific state, something like an application wide broadcast to all UI components so when they are displayed the user knows what state the application is in.
1

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.

2 Comments

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. I dont think the singleton approach will work that way.
@Donal: Then I can think a state design pattern will do here, where allow an object to alter its behavior when the state changes. Your Button object will change its behavior at the same time when UI changes its state.You can create separate class and connect them by weak bindings. Well I am not sure, but I think this a better approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.