3

我有某种操作表 UIView,它在点击其中的按钮后调用 MFMailComposeViewController,MFMailComposeViewController 被调用并成功呈现,但是当我点击取消时它不会关闭,有时会崩溃,我知道这是一个已知问题,但我已经尝试了所有已知的修复方法,但它对我不起作用。那是我的代码:

发送反馈.h:

#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>

@interface SendFeedback : UIView <UITableViewDelegate, UITableViewDataSource, MFMailComposeViewControllerDelegate, UINavigationControllerDelegate>

//Useless code to the problem.    

@property (nonatomic, retain) MFMailComposeViewController *feedBackComposer;

@end

发送反馈.m:

- (void)baseInit
{
    //Useless code to the problem. 

    feedBackComposer = [[MFMailComposeViewController alloc] init];
    [feedBackComposer setMailComposeDelegate:self];
    [feedBackComposer setToRecipients:[NSArray arrayWithObject:@"info@getibox.com"]];
    [feedBackComposer setMessageBody:@"" isHTML:NO];
    [feedBackComposer setSubject:@"What I Love About iBox"];
}

并调用作曲家: - (void)sendFeedbackComposer { [self.window.rootViewController presentViewController:feedBackComposer animated:YES completion:nil]; }

解雇它:

- (void)mailComposeController:(MFMailComposeViewController *)feedBackComposer didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    //This method doesn't get called.

    [self.window.rootViewController dismissViewControllerAnimated:YES completion:nil];

    NSLog(@"Error: %@", error);
}

编辑:所以,这个问题中提供的所有答案都是正确的,这都是我的错。我想要做的是:我有一个UINavigationController包含一个UITableViewcells该视图中应该触发一个操作表,它是UITableView通过将它添加为 asubview,就像前一个一样,这个视图也包括cells并且其中一个将执行动作,它正在调用一个MFMailComposeViewController,即使我设置了它的委托并且所有方法都正确,它也被调用但没有成功解散,问题的原因是调用的方式MFMailComposeController,我首先从超级视图中删除了一点UITableView然后提出了MFMailComposeController,所以当我解雇邮件作曲家时,它甚至没有给出结果就崩溃了,这让我将崩溃的原因与委托方法混淆了,愚弄我。这是代码:

- (void)removeView
{
    if (self) {
        [UIView animateWithDuration:0.3
                         animations:^{backgroundView.alpha = 0;}
                         completion:^(BOOL finished){

        [UIView animateWithDuration:.3
                         animations:^{self.frame = CGRectMake(0, 568, 320, 568);}
                         completion:^(BOOL finished){[self removeFromSuperview];}];
        }];
    }
}
- (void)sendFeedbackComposer
{
    feedBackComposer = [[MFMailComposeViewController alloc] init];
    [feedBackComposer setMailComposeDelegate:self];
    [feedBackComposer setToRecipients:[NSArray arrayWithObject:@"info@getibox.com"]];
    [feedBackComposer setMessageBody:@"" isHTML:NO];
    [feedBackComposer setSubject:@"What I Love About iBox"];

    [self.window.rootViewController presentViewController:self.feedBackComposer animated:YES completion:nil];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 2: //That's the index of the MailComposer caller.
            [self removeView];
            [self sendFeedbackComposer];
            break;
        case 6:
            [self removeView];
            break;
        default:
            break;
    }
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    [feedBackComposer.presentingViewController dismissViewControllerAnimated:YES completion:nil];

    NSLog(@"Error: %@", error);
}

感谢 Stefan Atanasov、Jim 和 Vitaly S。

4

4 回答 4

3

你确定没有调用委托方法吗?我做了一个测试,它被称为,但要解雇邮件作曲家,请使用这样的代码:

[feedBackComposer dismissViewControllerAnimated: YES completion: nil];

在视图实现中实现委托也很奇怪,而不是在视图控制器中

于 2014-01-25T15:23:39.600 回答
2

为 Vitaly S. 的答案添加一些内容(由于缺乏声誉,我无法直接评论它,抱歉) - 调用了委托方法,所以问题是解雇。你可以试试这个:

[feedBackComposer.presentingViewController dismissViewControllerAnimated: YES completion: nil];
于 2014-01-25T15:41:10.733 回答
1

委托方法需要从 viewController 中调用,而不是从 UIView 中调用。

您调用 UIView 的视图控制器将拥有您的代表

<UITableViewDelegate, UITableViewDataSource, MFMailComposeViewControllerDelegate, UINavigationControllerDelegate>

在它的头文件中。

您需要创建一个委托方法来将信息从 UIView 传递给控制器​​,控制器将依次调用邮件和表格委托方法。

这是一个问题的链接,该链接演示了如何使用委托协议从 UIView 触发视图控制器中的方法。

从其视图触发 UIViewController 中的方法

希望这会有所帮助,吉姆

于 2014-01-25T15:16:16.877 回答
0

您需要通过检查 MFMailComposeViewController 是否可以响应来检查设备是否配置为发送邮件。

  if([MFMailComposeViewController canSendMail]){
  //your code
  }
于 2014-01-26T09:21:02.437 回答