0

起動画面を表示する Cocoa アプリケーションがあります。ユーザーからいくつかの情報を収集した後、それが有効かどうかを確認します。有効な場合は、緑色のチェックマークを表示してから 1 秒待ってから、起動ウィンドウをメイン アプリケーション ウィンドウにクロスフェードします。2 つの Window xib ファイルを持つ 2 つの NSWindowControllers があります。

私のstartupWindowController場合、上で説明したことを行うボタン アウトレットをセットアップしました。

- (void)fadeOutAndPresentMainWindow {

    // Initialize the main window from XIB
    mainWindowController = [[MyMainWindowController alloc] init];
    NSWindow *mainWindow = [mainWindowController window];

    // Position the main window BEHIND the currently visible startup window
    NSWindow *startupWindow = [startupController window];
    [mainWindow setFrame:[startupWindow frame] display:NO];
    [mainWindow orderWindow:NSWindowBelow relativeTo:[startupWindow windowNumber]];

    // Now wait 1 second and fade out the startupWindow to reveal the main window
    // that is behind it.
    double delayInSeconds = 1.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

        [NSAnimationContext beginGrouping];
        [[NSAnimationContext currentContext] setCompletionHandler:^{

            // releases when closed
            [startupWindow close];

            // deallocates the startup controller *after* the animation? or not...
            [startupWindowController release]; 
            startupWindowController = nil;
        }];

        // Do the fade
        [[startupWindow animator] setAlphaValue:0.0f];
        [NSAnimationContext endGrouping];

        // Now make the main window key
        [mainWindow makeKeyWindow];
    });
}

IBOutlet これはすべてうまく機能しますが、問題が 1 つあります。ユーザーがフェード アニメーション中にの付いたボタンをクリックすると、アプリケーションがクラッシュします。 MyStartupController performSelector:withObject:]: message sent to deallocated instance 0x102c00a90. 問題はstartupController、アニメーションが完了する前に割り当てが解除されていることです。

したがって、フェードアウト後にこのウィンドウコントローラーを適切に解放する方法がわかりません。これを達成する方法はありますか?

4

1 に答える 1