1

私のメイン ウィンドウ コントローラーには、モーダル シートの表示をトリガーするツールバー項目があります。このシートは、時間のかかる非同期プロセス (ローカル データをサーバーと同期するなど) の進行状況を表示することになっています。

ただし、(不確定な)進行状況インジケーターをアニメーション化することはできません。

これは、モーダル シートをトリガーするアクションです。

var syncProgressWindowController: SyncProgressWindowController!

// ...

@IBAction func syncWithServer(_ sender: AnyObject) {

    // (Actual HTTP code not implemented)

    syncProgressWindowController = SyncProgressWindowController()
    syncProgressWindowController.loadWindow()

    guard let modalWindow = syncProgressWindowController.window else {
        return
    }

    self.window?.beginSheet(modalWindow, completionHandler: { (response) in
        // THIS GETS EXECUTED. 
        // However, the code below has no effect:   

        self.syncProgressWindowController.progressIndicator.startAnimation(self)

        // self.syncProgressWindowController.progressIndicator is 
        // NOT nil, despite windowDidLoad() not being called
        // (see below)
    })
}

モーダル シート ウィンドウ コントローラー (SyncProgressWindowController上記のクラス) は、次のように定義されます。

@IBOutlet weak var progressIndicator: NSProgressIndicator!


convenience init() {
    self.init(windowNibName: "SyncProgressWindow")
}

override func windowDidLoad() {
    super.windowDidLoad()
    // Breakpoints here don't work, logs don't print to the console.
    // Not called? But outlet _is_ set (see above).
}

xib ファイル (SyncProgressWindow.xib) には次のものがあります。

  • 「SyncProgressWindowController」に設定されたファイルの所有者 ID/クラス
  • ウィンドウには、ファイルの所有者への新しい参照アウトレットがありますwindow
  • ウィンドウにはdelegate「ファイルの所有者」に配線されたアウトレットがあります(念のため-ただし、デリゲートメソッドも呼び出されないようです)。
  • ウィンドウの「起動時に表示」がオフになっています (したがって、問題なくモーダルに表示されます)。
  • 進行状況には、ファイルの所有者の に配線された新しい参照アウトレットがありますprogressIndicator

でも:

  1. SyncProgressWindowControllerwindowDidLoad()呼び出されません(実行はブレークポイントで停止せず、ログは出力されません)。
  2. progressIndicatorそれにもかかわらず、次のようなコードを使用して、アニメーション化しようとしてもアプリがクラッシュしないため、プロパティ/アウトレットは何らかの形で設定されています。
    self.syncProgressWindowController.progressIndicator.startAnimation(self)

私は何が欠けていますか?

4

1 に答える 1

1

endSheet(_:returnCode:)でシートを閉じると、 completedHandlerが起動されるため、シートが閉じられる前にインジケーターを開始します。

xibファイルが苦手なのですが、で行を無効loadWindowにしたらwindowDidLoadが呼ばれました。それが正しい方法かどうかはわかりません。

于 2016-08-16T05:03:31.530 に答える