我已经对这个问题进行了搜索,但没有找到答案,这导致我在这里写下我的第一个问题。
问题是当我按下调用下面方法的按钮时,我在这一行得到一个异常:[self presentModalViewController:mailViewController animated:YES];
异常是:
*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSCFString 计数]:无法识别的选择器发送到实例 0x20f6c”
此外,如果有帮助,我会在模拟器上运行我的应用程序。
我从这里得到了代码的大部分。
这是我的代码(电子邮件地址为空白):
// 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];
}
似乎是什么导致了异常?