首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MFMailComposeViewController提起NSException

MFMailComposeViewController提起NSException
EN

Stack Overflow用户
提问于 2011-04-05 10:12:08
回答 2查看 577关注 0票数 0

我已经做了这个问题的搜索,但没有找到答案,这导致我写我的第一个问题在这里。

问题是,当我按下下面调用metho的按钮时,我在这一行上得到了一个异常:[self presentModalViewController:mailViewController animated:YES];,而异常是:

*由于“NSInvalidArgumentException”异常终止应用程序,原因:'-NSCFString计数:发送到实例0x20f6c的未识别选择器‘

此外,如果这有帮助的话,我正在模拟器上运行我的应用程序。

我从这里获得了代码的大部分内容。

这是我的代码(删除电子邮件地址):

代码语言:javascript
复制
    // set up the email address array
    NSArray *email = [[NSArray alloc] initWithObjects:@"foo", nil];

    // Set up the view controller
    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
    mailViewController.mailComposeDelegate = self;

    // Set up the email to send to
    [mailViewController setSubject:@"foo"];
    [mailViewController setToRecipients:[email objectAtIndex:0]];

    // Get the path to the plist
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsPath = [paths objectAtIndex:0];  
    NSString *path = [documentsPath stringByAppendingPathComponent:@"foo.plist"];

    // Get the plist from the path
    NSData *myData = [NSData dataWithContentsOfFile:path];
    [mailViewController addAttachmentData:myData mimeType:@"plist" fileName:@"foo"];

    // Fill out the email body text 
    NSString *emailBody = @"Attached PLIST file";
    [mailViewController setMessageBody:emailBody isHTML:NO];

    // Release the array
    [email release];

    if (mailViewController != nil) {
        [self presentModalViewController:mailViewController animated:YES];
        [mailViewController release];
    }

是什么导致了这一异常?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-04-05 10:16:30

setToRecipients中,必须指定数组,而不是字符串。这样你就可以通过你的email-array。

票数 2
EN

Stack Overflow用户

发布于 2011-04-05 10:17:01

代码语言:javascript
复制
-(IBAction)btnemail:(id)sender{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

[picker setSubject:@"subject"];
NSString *emailid=btnEmail.titleLabel.text;
NSArray *toRecipients = [NSArray arrayWithObject:emailid];
[picker setToRecipients:toRecipients];

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

if ([MFMailComposeViewController canSendMail]) {
    [self.parentViewController presentModalViewController:picker animated:YES];
}else {

}
[picker release];

}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5550277

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档