iOS应用中的“解析问题 - 预期声明”

时间:2014-02-13 09:55:42

标签: ios objective-c mfmailcomposeviewcontroller

我的代码显示“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 个答案:

答案 0 :(得分:1)

试试这段代码:

-(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];
    }
}

答案 1 :(得分:1)

问题在于您的-(IBAction)email方法。它有一个没有大括号的else语句。只需删除它并重新运行。

-(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];
    }
}