当我进入Iphone邮件列表时,Iphone应用程序正在崩溃

当我进入Iphone邮件列表时,Iphone应用程序正在崩溃,iphone,objective-c,ios,xcode,mfmailcomposer,Iphone,Objective C,Ios,Xcode,Mfmailcomposer,在我的iphone应用程序中。我正在使用MFMailComposeViewController创建Iphone邮件聊天表。现在,当我第二次进入邮件列表时,我的应用程序正在崩溃。我在谷歌上搜索。但我找不到解决办法。有人帮我解决问题吗。请查看下面的代码,并帮助我哪里做错了 if ([MFMailComposeViewController canSendMail]) { controller = [[MFMailComposeViewController all

在我的iphone应用程序中。我正在使用
MFMailComposeViewController
创建Iphone邮件聊天表。现在,当我第二次进入邮件列表时,我的应用程序正在崩溃。我在谷歌上搜索。但我找不到解决办法。有人帮我解决问题吗。请查看下面的代码,并帮助我哪里做错了

if ([MFMailComposeViewController canSendMail])
        {
            controller = [[MFMailComposeViewController alloc] init];
            controller.mailComposeDelegate = self;
            [controller setSubject:@""];
            [controller setToRecipients:array1];
            [controller setMessageBody:@"" isHTML:NO];
            [controller setMailComposeDelegate: self];
            [controller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
            [self.navigationController presentModalViewController:controller animated:NO];
            [controller release];
        }

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{
    if(result == MFMailComposeResultSent)
    {
        [[self parentViewController] dismissModalViewControllerAnimated:YES];
    }
    else if (result == MFMailComposeResultCancelled)
    {
        [[self parentViewController] dismissModalViewControllerAnimated:YES];
    }
 }

我认为这一准则提出了问题:

[[self parentViewController] dismissModalViewControllerAnimated:YES];
代替上述用途:

[self dismissModalViewControllerAnimated:YES];

尝试编写此委托方法,而不是编写相同的方法

让我知道它是否有效

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
switch (result)
{
    case MFMailComposeResultCancelled:
        NSLog(@"canceled");
        break;
    case MFMailComposeResultSaved:
        NSLog(@"saved");
        break;
    case MFMailComposeResultSent:
        NSLog(@"sent");
        [self showErrorMessage: @"Email sent successfully"];
        break;
    case MFMailComposeResultFailed:
        NSLog(@"failed");
        [self showErrorMessage: @"Failed to send email"];
        break;
    default:
        NSLog(@"not sent");
        break;
}
[self dismissViewControllerAnimated:YES completion:nil];

}
快乐编码

替换此代码:

[self.navigationController presentModalViewController:controller animated:NO];
与:


在打开邮件视图的方法中,用下面的代码替换您的代码。并告诉我它是否工作!!!!!!编码快乐

 MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

if ([MFMailComposeViewController canSendMail] == NO) {
        return;
}
else
{
    picker.mailComposeDelegate = self;
    NSString *stringtitle=[NSString stringWithFormat:@"Apple"];
    [picker setSubject:stringtitle];

    NSData *imgDataLoop = UIImagePNGRepresentation(shaereImage.image);

    [picker addAttachmentData:imgDataLoop mimeType:@"image/png" fileName:@"rainy"];

    [self presentViewController:picker animated:YES completion:nil];
    [picker release];

}

将您的方法更改为

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"canceled");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"saved");
            break;
        case MFMailComposeResultSent:
            NSLog(@"sent");
            [self showErrorMessage: @"Email sent successfully"];
            break;
        case MFMailComposeResultFailed:
            NSLog(@"failed");
            [self showErrorMessage: @"Failed to send email"];
            break;
        default:
            NSLog(@"not sent");
            break;
    }
    [self dismissViewControllerAnimated:YES completion:nil];

}

-(void)showErrorMessage:(NSString *)iMessage
{
        NSLog(@"%@", iMessage);
}
正如我前面提到的,在调用和定义部分中,您的方法签名是不同的。如上图所示,这两个位置应相同


调用该方法时为
[self-message:@“发送电子邮件失败”]但在定义中,您不接受字符串部分。您需要有一个相同的输入参数。您也可以将其称为
[self-message]
然后保持消息的
方法的原样。

谢谢您的回复。很抱歉我明白了。现在,当我在邮件工作表中输入第二次时,我单击“发送”按钮。我的应用程序正在崩溃。我能做什么。这个问题出了什么问题?@Gopinath,你能给我们提供崩溃日志吗?@Gopinath:请检查导航控制器视图的viewwilldisease和viewdidedisease方法class@Aadhira谢谢你的回复-[myViewContrl消息:]:无法识别的选择器已发送到实例0x883a400@Gopinath:然后问题是消息方法调用。你把那个方法称为什么?还可以查看我之前的评论,您使用的是哪个版本的xcode?@Rocks谢谢您的回复。Ios5.您的NSLog显示了什么错误?@PratyushaTerli感谢您的回复。NSlog显示空值。请检查您的控制台,看看是否有任何崩溃消息?复制粘贴控制台日志语句并粘贴到问题中。如果没有崩溃消息,请键入bt并在控制台中按enter键。谢谢您的帮助。但当我在邮件表中输入秒结束时间时,我点击了发送按钮。然后我的应用程序崩溃了。但在我的控制台里,我发现了这个错误-[myviewcontroler淋浴RorMessage:]:无法识别的选择器已发送到实例0x883A400感谢您的回复。抱歉。我在控制台中发现了这个错误-[myViewCotroler消息:]:无法识别的选择器已发送到实例0x9839a00@Gopinath,删除
[自我提示信息:
并检查。@ACB我可以知道此问题的原因吗?@Gopinath,您需要发布您的
提示信息和调用此方法的行。这两者之间存在严重不匹配。这就是崩溃的原因。@ACB抱歉延迟。请稍候。
-(void)mail
{ 
  if ([MFMailComposeViewController canSendMail])
    {

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

    [mailController setSubject:@"your Subject"];
    [mailController setMessageBody:@"your message" isHTML:NO];

    UIImage *tmp = [UIImage imageNamed:@"Icon.png"];
    NSData *myData = UIImageJPEGRepresentation(tmp, 1.0);

    [mailController addAttachmentData:myData mimeType:@"image/png" fileName:@"MyPhoto.png"];
    if (arrTo)
        [mailController setToRecipients:arrTo];

    [self presentModalViewController:mailController animated:YES];
    return YES;
}
else {
    return NO;
}
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{   

    [controller dismissModalViewControllerAnimated:YES];
}
-(void)mail
{ 
  if ([MFMailComposeViewController canSendMail])
    {

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

    [mailController setSubject:@"your Subject"];
    [mailController setMessageBody:@"your message" isHTML:NO];

    UIImage *tmp = [UIImage imageNamed:@"Icon.png"];
    NSData *myData = UIImageJPEGRepresentation(tmp, 1.0);

    [mailController addAttachmentData:myData mimeType:@"image/png" fileName:@"MyPhoto.png"];
    if (arrTo)
        [mailController setToRecipients:arrTo];

    [self presentModalViewController:mailController animated:YES];
    return YES;
}
else {
    return NO;
}
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{   

    [controller dismissModalViewControllerAnimated:YES];
}