Frage

I'm a beginner at iOS programming, so I'm probably asking something obvious. Anyway, I have a UISwitch in my storyboard correctly connected to a property called mySwitch declared in my UIViewController. I'd like to know how to access that property from inside my app delegate. For instance, from inside applicationWillResignActive:

- (void)applicationWillResignActive:(UIApplication *)application
{
    ??? // don't know how to access the mySwitch property
    if ([mySwitch isOn]) {
        // perform some task
    }
}

The answer I'm looking for will probably satisfy the more general question "What's the correct way to access a view object from my app delegate?" to which I haven't found an answer. Any help is really appreciated.

War es hilfreich?

Lösung

You shouldn't be trying to - that isn't what the app delegate is for. Or, depending on the task, the state of the switch should be stored to user defaults or something like that.

If the view controller should do that job, it can do this by observing the UIApplicationWillResignActiveNotification notification (if it really needs to be done then).

If the app delegate should do the job then the view controller should update the value in NSUserDefaults whenever the switch is changed.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top