Jared Collett Jared Collett - 2 months ago 8
iOS Question

iOS Alert to user with contents of a UITextField when resuming app

I'm trying to send an alert containing the contents of a UITextField in my

MainViewController
when the app is resumed from multi-tasking. I'm trying to use the
AppDelegate
's
applicationDidBecomeActive
method. My main issue is accessing the contents of the
textField
in the
ViewController
from
AppDelegate
.

AppDelegate :

- (void)applicationDidBecomeActive:(UIApplication *)application
{
UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:nil
message:CONTENTS OF UITEXTFIELD
delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
}

Answer

It's a bad practice to store anything in UI. If your only source of data is some string displayed via label or text view it's a design flaw. You should store this value as text and obtain it via some public interface.

You can store some reference to the ViewController in AppDelegate or use NSUserDefaults saving your data when app goes to background.