邮件和邮件不会从警报视图中删除

时间:2014-03-17 15:25:45

标签: ios objective-c email message alert

我有一个UIAlertView,可以启动电子邮件和消息屏幕。当用户点击“警报”按钮时,两个视图都会打开,但是它们不会关闭。

我试过添加:

-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    [self dismissModalViewControllerAnimated:YES];
}
然而,对于班级的主体,它没有帮助。

以下是电子邮件的呈现方式:

    [viewController presentViewController:email animated:YES completion:nil];

编辑以下是我用来呈现电子邮件的完整代码:

//send email...
-(void)sendEmail{

    //mail composer
    Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
    if(mailClass != nil){
        if([mailClass canSendMail]){

            //get the current view controller from the App Delegate
            apptester_appDelegate *appDelegate = (apptester_appDelegate *)[[UIApplication sharedApplication] delegate];
            UIViewController *viewController = [appDelegate getViewController];

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

            //navigation bar color depends on iOS7 or lower...
            if(floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1){
                [[email navigationBar] setTintColor:[UIColor blackColor];
            }else{
                [[email navigationBar] setBarTintColor:[UIColor blackColor]];
            }

            //show the model view...
            [viewController presentViewController:email animated:YES completion:nil];

        }
    }
}

是否有其他人遇到此错误?

这可能不相关,但此应用有一个标签栏。

3 个答案:

答案 0 :(得分:1)

确保您已设置邮件控制器的委托

   mail.mailComposeDelegate = viewController;

也可以试试这个,

    [viewController.tabBarController presentViewController:email animated:YES completion:nil];

您是否尝试过此方法并传递“controller”而不是self:

   -(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
    {
       [controller dismissViewControllerAnimated:YES completion:nil];
    }

谢谢!

答案 1 :(得分:0)

显示控制器以解除模态视图的责任。确保在演示控制器中实现模态的委托。

答案 2 :(得分:0)

两件事:

1)确保在出示之前在mailComposeDelegate上设置MFMailComposeViewController

2)在mailComposeController:didFinishWithResult:error:方法中,您应该:

[controller dismissModalViewControllerAnimated:YES];