PDA

View Full Version : NSError and UIAlertView Problem




newtoiphonesdk
Aug 25, 2010, 10:56 AM
I am setting up MFMailComposer within app. I want it to have a UIAlertView display the results of sending the email. I have this code installed:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
message.hidden = NO;
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:{
UIAlertView *cancelled = [[UIAlertView alloc] initWithTitle:@"Results" message:@"Email Was Cancelled" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[cancelled show];
[cancelled release];}

case MFMailComposeResultSaved:{
UIAlertView *saved = [[UIAlertView alloc] initWithTitle:@"Results" message:@"Email Draft Saved" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[saved show];
[saved release];}

case MFMailComposeResultSent:{
UIAlertView *sent = [[UIAlertView alloc] initWithTitle:@"Results" message:@"Email Sent" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[sent show];
[sent release];
}
case MFMailComposeResultFailed:{
UIAlertView *failed = [[UIAlertView alloc] initWithTitle:@"Results" message:@"Email Failed To Send, Please Check Internet Connection And Try Again." delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[failed show];
[failed release];
}
}
[self dismissModalViewControllerAnimated:YES];
}

However, when I debug, no matter what I press, every UIAlertView will pop up. What is the cause of this?



chown33
Aug 25, 2010, 11:37 AM
You have no break statements.

Read a C or Objective-C language reference. Learn about switch and how case falls through without a break.

Overview article:
http://en.wikipedia.org/wiki/Switch_statement

sherry2009
Aug 25, 2010, 10:07 PM
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
message.hidden = NO;
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:{
UIAlertView *cancelled = [[UIAlertView alloc] initWithTitle:@"Results" message:@"Email Was Cancelled" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[cancelled show];
[cancelled release];
break;
}

case MFMailComposeResultSaved:{
UIAlertView *saved = [[UIAlertView alloc] initWithTitle:@"Results" message:@"Email Draft Saved" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[saved show];
[saved release];
break;
}

case MFMailComposeResultSent:{
UIAlertView *sent = [[UIAlertView alloc] initWithTitle:@"Results" message:@"Email Sent" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[sent show];
[sent release];
break;
}
case MFMailComposeResultFailed:{
UIAlertView *failed = [[UIAlertView alloc] initWithTitle:@"Results" message:@"Email Failed To Send, Please Check Internet Connection And Try Again." delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[failed show];
[failed release];
break;
}
}
[self dismissModalViewControllerAnimated:YES];
}