I'm calling a method I've written in app delegate which calls an alertView to ask the user for a password, I use the method in applicationWillEnterForeground also.
So the value is set in clickedButtonAtIndex in a开发者_Python百科pp delegate.
How do I determine when the value has been set in the view controller (where I'm calling the method) ?
The simplest way to do this would be to delegate back to your viewController.
Your app delegate will have the ability to access the pointers to any ViewControllers/navControllers that you have. (scope depends on your design of course)
Here is a good Post on objective-c delegates.
I found myself doing this kind of thing quite often to simplify the process i had a method contained in a singleton that i called 'toolbox' that went something like this.
-(void)showAlertWithTitle:(NSString*)_title Message:(NSString*)_message CancelButtonTitle:(NSString*)_cancelTitle AlternitiveButtonTitle:(NSString*)alternitiveButtonTitle AndDelegate:(id)del
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:_title message:_message delegate:del cancelButtonTitle:_cancelTitle otherButtonTitles:alternitiveButtonTitle, nil];
[alert show];
[alert release];
}
This meant that i could call an alert where i wanted and have the Alert delegate back to where i wanted, then just implement UIAlertViewDelegate
there.
精彩评论