1

我对 object-c 中的调用方法处理有疑问。

我下载了邮件编写器的苹果示例代码(http://developer.apple.com/iphone/library/samplecode/MailComposer/Introduction/Intro.html)。

当用户触摸示例代码中的“撰写邮件”按钮时,Methode

-(void)displayComposerSheet 
{
    NSLog(@"MCVC displayComposerSheet");
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"Hello from California!"];


    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 

    [picker setToRecipients:toRecipients];
    [picker setCcRecipients:ccRecipients];  
    [picker setBccRecipients:bccRecipients];

    // Attach an image to the email
    NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
    NSData *myData = [NSData dataWithContentsOfFile:path];
    [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];

    // Fill out the email body text
    NSString *emailBody = @"It is raining in sunny California!";
    [picker setMessageBody:emailBody isHTML:NO];

    [self presentModalViewController:picker animated:YES];
    [picker release];
}

将被加载并出现 mailcomposerview。

用户发送邮件或取消邮件后,将调用以下方法

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
    NSLog(@"MCVC mailComposeController");
    message.hidden = NO;
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            message.text = @"Result: canceled";
            break;
        case MFMailComposeResultSaved:
            message.text = @"Result: saved";
            break;
        case MFMailComposeResultSent:
            message.text = @"Result: sent";
            break;
        case MFMailComposeResultFailed:
            message.text = @"Result: failed";
            break;
        default:
            message.text = @"Result: not sent";
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}

您可以在其中实现您的代码。

我现在的问题是如何获取例如“toRecipients”、“ccRecipients”、“setMessageBody”、“setSubject”等的数据?

这甚至可能吗?我不知道如何在"- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error"-Methode

如果我忘记了您需要的任何信息,我会发布它们:)

感谢所有可以帮助我的人:)

4

1 回答 1

1

来自苹果 API:

重要提示:邮件撰写界面本身不可定制,并且不得由您的应用程序修改。此外,在呈现界面后,您的应用程序不允许对电子邮件内容进行进一步的更改。用户仍然可以使用界面编辑内容,但程序更改会被忽略。因此,您必须在呈现界面之前设置内容字段的值。

看着这个,并尝试在 didFinishWithResult: 方法中尝试适合 ivars 的各种名称,似乎不可能从预构建的 MFMailComposeViewController 获取此信息

你可以继承这个类或滚动你自己的来获得功能..但这似乎是唯一的方法。

于 2010-07-12T18:20:40.840 回答