1

I have no idea why this is happening. It looks correct to me. I wrote another UIAlertView and it looked like it would be fine and as soon as I deleted this one it error-ed the one I wrote. I'm trying to follow this tutorial.

This is in my viewcontroller.m

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{


switch (result) {
        case MessageComposeResultCancelled:
            NSLog(@"Cancelled");
            break;
        case MessageComposeResultFailed:
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome To My App" message:@"This app will ... First you need to ..." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];
            [alert release];

        break;
    case MessageComposeResultSent:

        break;
    default:
        break;
}

[self dismissModalViewControllerAnimated:YES];
}

The errors are showing up on numerous lines of it such as: Missing "[" at start of message send expression. (If I have it put it in it wants to put another and another and another after initWithTitle:)

Next error is: Use of undeclared indentifier 'alert' (says this at the show and release)

Any idea what is going on? Thanks in advance.

steven
  • 698
  • 3
  • 8
  • 32
  • see these SO questions: http://stackoverflow.com/questions/1231198/declaring-variables-inside-a-switch-statement http://stackoverflow.com/questions/1115304/can-i-declare-variables-inside-an-objective-c-switch-statement – tipycalFlow Oct 06 '11 at 16:14
  • yours is a typical case statement declaration error ! And Travis has given the solution... – tipycalFlow Oct 06 '11 at 16:14

2 Answers2

6

Try adding brackets to your case statement that has multiple lines.

- (void)messageComposeViewController:(MFMessageComposeViewController
*)controller didFinishWithResult:(MessageComposeResult)result {


switch (result) {
        case MessageComposeResultCancelled:
            NSLog(@"Cancelled");
            break;
        case MessageComposeResultFailed: {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome To My App" message:@"This app will ... First you need to ..." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];
            [alert release];

        break;
        }
    case MessageComposeResultSent:

        break;
    default:
        break; }

[self dismissModalViewControllerAnimated:YES]; }
Travis
  • 5,021
  • 2
  • 28
  • 37
0

why are You set the delegate, if you have not extra buttons in your Alert? I think, You should change delegate:self to delegate:nil.

Vov4yk
  • 1,080
  • 1
  • 9
  • 13