我的代码显示了一个"Parse问题-预期语句“错误,我不知道需要修改或添加什么来修复它。
-(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];
}发布于 2014-02-13 10:01:04
试试下面的代码:
-(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];
}
}发布于 2014-02-13 10:14:29
问题在于您的-(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];
}
}https://stackoverflow.com/questions/21750748
复制相似问题