"Проблема разбора - ожидаемое утверждение" в приложении для iOS

Мой код показывает ошибку "Parse Issue - Expected Statement", и я не знаю, что нужно изменить или добавить, чтобы исправить это.

-(IBAction)email {
    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
    [composer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
        [composer setToRecipients:[NSArray arrayWithObjects:@"matt_srfgtr@hotmail.com", nil]];
        [composer setSubject:@"subject here"];
        [composer setMessageBody:@"message here"isHTML:NO];
        [composer setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
        [self presentViewController:composer animated:YES completion:nil];
    }
    else
        }

Ожидаемая ошибка оператора показывает для этой фигурной скобки ^

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    if (error) {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle:@"error"
                              message:[NSString stringWithFormat:@"error %@", [error description]]
                              delegate:nil cancelButtonTitle:@"dismiss" otherButtonTitles:nil, nil];
        [alert show];
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }

2 ответа

Решение

Попробуйте этот код:

-(IBAction)email {
    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
    [composer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
        [composer setToRecipients:[NSArray arrayWithObjects:@"matt_srfgtr@hotmail.com", nil]];
        [composer setSubject:@"subject here"];
        [composer setMessageBody:@"message here"isHTML:NO];
        [composer setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
        [self presentViewController:composer animated:YES completion:nil];
    }
    else {

    }
}

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    if (error) {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle:@"error"
                              message:[NSString stringWithFormat:@"error %@", [error description]]
                              delegate:nil cancelButtonTitle:@"dismiss" otherButtonTitles:nil, nil];
        [alert show];
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

Проблема заключается в вашем -(IBAction)email метод. У него есть еще оператор без скобок. Просто удалите его и перезапустите.

-(IBAction)email {
    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
    [composer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
        [composer setToRecipients:[NSArray arrayWithObjects:@"matt_srfgtr@hotmail.com", nil]];
        [composer setSubject:@"subject here"];
        [composer setMessageBody:@"message here"isHTML:NO];
        [composer setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
        [self presentViewController:composer animated:YES completion:nil];
    }
}
Другие вопросы по тегам