1

さて、これはしばらくの間私を悩ませてきました...

私は確認しましたが、他のすべての質問/回答は非ARCプロジェクトに関するものです。

MFMCvcを提示し、メッセージをすぐにキャンセルすると、iPhoneでThread1:EXEC_BAD_ACCESSエラーメッセージが表示されます。iPadで正常に動作するか、少し置いておくと(たとえば、30秒以上)動作します

何かアドバイスはありますか?(タイマーを入れて、タイマーが切れるまで閉じない以外は?)

ところで、私はMFMessageComposeViewControllerでも同じことをしていて、iPhoneとiPadの両方で正常に動作します。

これがそれを提示するための私のコードです

if (([action isEqualToString:@"EMail"]) && contact.length>0)
{
    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
    if([MFMailComposeViewController canSendMail]) {
        [mailViewController setSubject:@""];
        [mailViewController setMessageBody:@"" isHTML:NO];
        [mailViewController setToRecipients:[NSArray arrayWithObject:contact]];
        [mailViewController setMailComposeDelegate:self];
        [self presentModalViewController:mailViewController animated:NO];
    }
}

そして、ここで私はそれを却下します

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
    {
        switch (result)
        {
            case MFMailComposeResultCancelled:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send EMail" message:@"EMail Has Been Cancelled"
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                [alert show];
            }
                break;
            case MFMailComposeResultFailed:
            {
                NSLog(@"Error");
            }
                break;
            case MFMailComposeResultSent:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send EMail" message:@"EMail Has Been Sent"
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                [alert show];
            }
                break;
            case MFMailComposeResultSaved:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send EMail" message:@"EMail Has Been Saved"
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                [alert show];
            }
                break;
            default:
                break;
        }
        [self dismissModalViewControllerAnimated:NO];
    }
4

2 に答える 2

5

1)次の行ではありません:[self dismissModalViewControllerAnimated:NO];-次のようにする必要があります:[controller dismissModalViewControllerAnimated:NO];?MFMailComposeViewControllerを閉じたいと考えています。

2)MFMailComposeViewControllerが保持されないという問題もある可能性があります。このクラスを使用したときに、コントローラーのプロパティを作成しました。これは試す価値があるかもしれません。

// in the interface definition
 @property (nonatomic, strong) MFMailComposeViewController* mailComposer;

その後

// at creation time
if (([action isEqualToString:@"EMail"]) && contact.length>0)

if(![MFMailComposeViewController canSendMail]) return; // bail early if can't send mail

MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
[mailViewController setSubject:@""];
[mailViewController setMessageBody:@"" isHTML:NO];
[mailViewController setToRecipients:[NSArray arrayWithObject:contact]];
[mailViewController setMailComposeDelegate:self];
[self presentModalViewController:mailViewController animated:NO];

[self setMailComposer: mailViewController];
// if not using ARC then:  [mailViewController release];

そしてdidFinishで

 [[self mailComposer] dismissModalViewControllerAnimated:YES];
 [self setMailComposer: nil];
于 2012-05-18T18:20:23.533 に答える
1

[self dismissModalViewControllerAnimated:NO]をdidFinishWithResult関数の先頭に移動します。つまり、アラートビューを表示する前に、メールビューを閉じます。これでクラッシュが解消されるかどうかはわかりませんが、それでも、これを行う必要があります。

于 2012-05-18T16:39:18.833 に答える