3

古いアプリの更新で問題が発生しています。これは、Xcode 4.5 に更新し、iOS6 で試してみて、次のエラーが発生したためです。

*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View <MainView: 0x1e818620; frame = (0 0; 320 476); autoresize = RM+BM; layer = <CALayer: 0x1e818750>> is associated with <MainViewController: 0x1e811850>. Clear this association before associating this view with <UIViewController: 0x21149860>.'

* First throw call stack: (0x377d82a3 0x35ae897f 0x377d81c5 0x38b0dd7b 0x38b0dc6b 0x1dc25 0x38b940ad 0x38b9405f 0x38b9403d 0x38b938f3 0x38b93de9 0x38abc5f9 0x38aa9809 0x38aa9123 0x37c5c5a3 0x37c5c1d3 0x377ad173 0x377ad117 0x377abf99 0x3771eebd 0x3771ed49 0x37c5b2eb 0x38afd301 0x1bf03 0x1bea8) libc++abi.dylib: terminate called throwing an exception [Switching to process 9219スレッド 0x2403]

問題の原因はここにあると思います。

 mailComposer = [[UIViewController alloc] init];
[mailComposer setView:self];
[mailComposer setModalTransitionStyle: UIModalTransitionStyleCoverVertical];




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

アプリがクラッシュしたときのMFMailコンポーザーに移動するボタンをクリックしたときと同じです。

何か案は?

前もって感謝します

編集 - 最初の 3 行を削除しても、アプリはクラッシュしませんが、メール ビューは読み込まれません...ここにコード全体があります。

    // The actual mail window call



mailComposer = [[UIViewController alloc] init];
[mailComposer setView:self];
[mailComposer setModalTransitionStyle: UIModalTransitionStyleCoverVertical];




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

[picker setSubject:@"Hello How are you"];

    // Fill out the email body text
NSString *pageLink = @"http://www.apple.com"; 
NSString *iTunesLink = @"http://itunes.apple.com/gb/artist/randomer";
NSString *content = @"blah blah"; 


NSString *emailFileName = [NSString stringWithFormat:@"email_.html"];


NSString *emailFilePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: emailFileName];
NSString *body = [NSString stringWithContentsOfFile:emailFilePath encoding:NSUTF8StringEncoding error:nil];


body = [body stringByReplacingOccurrencesOfString:@"//TEXT_PLACEHOLDER//" withString:@"replace here"];
body = [body stringByReplacingOccurrencesOfString:@"//FRIENDNAME_PLACEHOLDER//" withString:pageLink];
body = [body stringByReplacingOccurrencesOfString:@"//ITUNES_PLACEHOLDER//" withString:  iTunesLink];
body = [body stringByReplacingOccurrencesOfString:@"//PASSKEY_PLACEHOLDER//" withString:  yourPassword];
body = [body stringByReplacingOccurrencesOfString:@"//PHONETIC_PLACEHOLDER//" withString:  yourPhoneticPassword];




[picker setMessageBody:body isHTML:YES];    
picker.navigationBar.barStyle = UIBarStyleBlack;    
[mailComposer presentModalViewController:picker animated:YES];
[picker release];

}

//HANDLE THE MAIL EVENTS
////////////////////////
  • (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { // インターフェイス スイッチに関連するエラーをユーザーに通知します (result) { case MFMailComposeResultCancelled: break; case MFMailComposeResultSaved: ブレーク; ケース MFMailComposeResultSent: ブレーク; ケース MFMailComposeResultFailed: ブレーク;

    default:
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email" message:@"Sending Failed - Unknown Error :-("
                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];
        [alert release];
    }
    
        break;
    

    } [mailComposer disconnectModalViewControllerAnimated:YES]; //[mailComposer.view.superview removeFromSuperview]; }

4

1 に答える 1

1

メール作成ビュー コントローラーを表示させる主な方法は、現在アクティブな UIViewController を使用して表示することです。これを明確にするために十分なコードを共有していませんでしたがself、そのコンテキストで UIViewController である場合は、次のことを行う必要があります。

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

selfが UIViewController でない場合はself、上記のコードを現在の UIViewController を参照する変数に置き換えます。

于 2012-11-04T12:14:41.930 に答える