UIActionSheet
s are not used that way:
- (IBAction)xButton:(UIButton*)sender
{
if ([_hasUserTakenAPhoto isEqual:@"YES"])
{
_xButtonAfterPhotoTaken = [[UIActionSheet alloc] initWithTitle:@"Delete Photo?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:nil];
[_xButtonAfterPhotoTaken showInView:self.view];
}
else
{
[self performSegueWithIdentifier:@"backToHomeFromMediaCaptureVC" sender:self];
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// Check if it's the correct action sheet and the delete button (the only one) has been selected.
if (actionSheet == _xButtonAfterPhotoTaken && buttonIndex == 0)
{
[self performSegueWithIdentifier:@"backToHomeFromMediaCaptureVC" sender:self];
}
}
- (void)actionSheetCancel:(UIActionSheet *)actionSheet
{
NSLog(@"Canceled");
}
You gotta understand that interface elements are not "instant", there's plenty of asynchrony going on. When presenting an UIActionSheet
for instance, the thread doesn't wait for the user to answer yes or no, it keeps running.
That's why there's delegates, and blocks, you present the UIActionSheet
, and with the delegate you say "I'll take care of it when the user actually clicks it".
You'd be wondering, why not just wait for it to select it? Main thread takes care of updating the interface, animations, and retrieving user input (touches, keyboard taps, etc) and even running NSTimers
that are subscript to the main NSRunLoop
. Stopping main thread would lock the interface.