0

我已经根据 Apple 提供的代码示例在我的应用程序中实现了标准邮件功能。我的代码如下

- (IBAction)mailBtnPressed:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
    mailer = [[MFMailComposeViewController alloc] init];

    [mailer setDelegate:self];

    [mailer setSubject:@"Een berichtje via de iPhone app"];         mailer.mailComposeDelegate = self;
    NSArray *toRecipients = [NSArray arrayWithObjects:@"studio@vrtfm.be", nil];
    [mailer setToRecipients:toRecipients];

    NSString *emailBody = @"";
    [mailer setMessageBody:emailBody isHTML:NO];

    [self presentModalViewController:mailer animated:YES];
}
else
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oeps..."
                                                    message:@"Dit toestel ondersteunt geen mail functionaliteit."
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
}

}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved: you saved the email message in the drafts folder.");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
            break;
        default:
            NSLog(@"Mail not sent.");
            break;
    }
        [self becomeFirstResponder];
    // Remove the mail view
    [self dismissModalViewControllerAnimated:YES];
}

点击发送按钮调用委托,一切正常。但是,点击取消按钮不会调用委托,它只会使视图变暗;该应用程序挂在那里。

注意: 我没有在我的应用程序中显示状态栏。

我没有使用 xib,而是代码[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

此邮件功能适用于 iOS5、iOS5.1。但仅在较低版本中面临问题。

我也尝试过使用[mailer setMailComposeDelegate:self];

我当前的班级 xib 的大小为 (280,480)。

我在单个视图中使用多个视图,其中包含内容大小 (1540,960) 的滚动视图。

使用方法显示视图[scrollView scrollRectToVisible:frame animated:YES];

4

1 回答 1

3

试试看这个例子

简短的回答:

尝试更改代码行

[mailer setDelegate:self];

mailer.mailComposeDelegate = self;
于 2012-08-17T07:52:31.023 回答