mailComposeDelegate和简单Delegate属性之间的区别 [英] Difference between mailComposeDelegate and simple Delegate property

查看:144
本文介绍了mailComposeDelegate和简单Delegate属性之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我在 MFMailComposeViewController 委托属性上感到困惑,当我设置 mailer.mailComposeDelegate 应用程序刚刚调用后崩溃 [self presentModalViewController:mailer animated:YES]; 当我执行 mailer.delegate 时,app不会崩溃但是发送邮件后,其视图无法隐藏,或者只是从导航蝙蝠按钮取消取消它。我被卡住了为什么会这样。
让我分享代码,你得到我在做错误的提示。

Hi i am getting confuse on MFMailComposeViewController delegate property, when i set mailer.mailComposeDelegate app crash just after call [self presentModalViewController:mailer animated:YES]; and when i do mailer.delegate then app don't crash but its view can't hide after sending mail or just cancel it from its navigation bat button "Cancel". I am getting stuck why this happen. Let me share code, you get hint where i am doing mistake.

if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
    if(mailer)
    {
        mailer.mailComposeDelegate = self;
        //mailer.delegate=self;
        [mailer setSubject:@"What the Buck?"];
        imageData = UIImagePNGRepresentation(screenImgSubCat);        

        [mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"testapp"];        
        NSString *emailBody = @"What the Buck?! – www.testapp.com";
        [mailer setMessageBody:emailBody isHTML:NO];
        [self presentModalViewController:mailer animated:YES];
        //[mailer release];

    }
}
}

更新

我更改了代码并使用 mailer.mailComposeDelegate = self; 并对此行发表评论 [邮件程序发布]; 在加载图片时仍然让我崩溃。
这是我在崩溃后得到的图像。

I change code and use mailer.mailComposeDelegate = self; and also comment this line [mailer release]; still giving me crash on when image is being loading. Here is the Image what i am getting after crash.

推荐答案

在.h文件中添加 MFMailComposeViewControllerDelegate

@interface VideoPlayAndSharing : UIViewController
<MFMailComposeViewControllerDelegate>  

Display ComposerSheet

Display ComposerSheet

-(void)displayComposerSheet
{
    if ((videodta.length/1024)/1024 < 25)
    {
        NSLog(@"Video size >> %d",videodta.length/1024);
        MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate = self;

        [picker setSubject:@"Your subject"];


        // Set up recipients
        NSArray *toRecipients = [NSArray arrayWithObject:@"rajneesh071@gmail.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];

        [picker addAttachmentData:videodta mimeType:@"video/mp4" fileName:@"MyPersonalMessage"];

        // Fill out the email body text
        NSString *emailBody = @"Type your message here";
        [picker setMessageBody:emailBody isHTML:NO];
        [self presentModalViewController:picker animated:YES];
    }
    else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"My Personal Message"
                                                        message:@"Video exceed the limit of 25 MB"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil, nil];
        [alert show];
    }
}

和委托方法

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
    // 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 dismissViewControllerAnimated:YES completion:nil];
}  

编辑

picker.mailComposeDelegate 其代表 MFMailComposeViewControllerDelegate

它回复 - (void)mailComposeController

picker.delegate 其代表 UINavigationControllerDelegate

它对导航控制器的响应不是 - (void)mailComposeController ,等取消点击它不会调用,这就是为什么你的 MFMailComposeViewController 视图没有隐藏。

Its respond to navigation controller not - (void)mailComposeController , so on cancel click it will not call, thats why your MFMailComposeViewController view is not hiding.

这篇关于mailComposeDelegate和简单Delegate属性之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆