2014-02-13 57 views
0

我的代碼顯示「Parse Issue - Expected Statement」錯誤,我不知道需要更改或添加哪些內容才能解決問題。iOS中的「解析問題 - 預期聲明」

-(IBAction)email { 
    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init]; 
    [composer setMailComposeDelegate:self]; 
    if ([MFMailComposeViewController canSendMail]) { 
     [composer setToRecipients:[NSArray arrayWithObjects:@"[email protected]", 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

有了正確的縮進,它就顯而易見了。 ;-)刪除電子郵件方法中的「else」。 –

回答

1

試試這個代碼:

-(IBAction)email { 
    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init]; 
    [composer setMailComposeDelegate:self]; 
    if ([MFMailComposeViewController canSendMail]) { 
     [composer setToRecipients:[NSArray arrayWithObjects:@"[email protected]", 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]; 
    } 
} 
+0

太棒了!完美地工作。非常感謝你! – user3230481

1

問題就出在你的-(IBAction)email方法。它有一個沒有括號的else語句。只要將其刪除並重新運行即可。

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