无法在iphone中的MFMailComposeViewController中设置Mailto字段

时间:2013-01-05 07:38:46

标签: iphone mfmailcomposeviewcontroller

我已经编写了代码来点击按钮发送邮件。但我有编程的电子邮件ID。 我有这样的输出。

email@gmail.com发送MailButton

现在当我点击Send MailButton然后它打开MFMailComposeViewController但是字段是空的。这里email@gmail.com是动态变化的,它不是固定的。

我的代码是

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

if([MFMailComposeViewController canSendMail])
{
    NSString *emailBody;
    emailBody=self.shareString;
    //NSLog(@"EMail Body ---- %@",emailBody);

    [picker setMessageBody:emailBody isHTML:YES];
    [picker becomeFirstResponder];

    [self presentModalViewController:picker animated:YES];
}

这里需要改变什么?

2 个答案:

答案 0 :(得分:1)

使用以下代码:

NSArray *tempArray = [[NSArray alloc] initWithObjects:@"abc@gmail.com", nil];
[picker setToRecipients:tempArray];

它适合我。

谢谢, Hemang。

答案 1 :(得分:0)

你需要先为这个创建一个数组。

-(void)displayComposerSheetEmailUs{

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setSubject:@"Hello from the App!"];

    // Set up recipients
             NSArray *toRecipients = [NSArray arrayWithObject:@"abc@gmail.com"]; 
             [picker setToRecipients:toRecipients];

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

    [self presentModalViewController:picker animated:YES];

}