私のメイン ウィンドウ コントローラーには、モーダル シートの表示をトリガーするツールバー項目があります。このシートは、時間のかかる非同期プロセス (ローカル データをサーバーと同期するなど) の進行状況を表示することになっています。
ただし、(不確定な)進行状況インジケーターをアニメーション化することはできません。
これは、モーダル シートをトリガーするアクションです。
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
。
でも:
SyncProgressWindowController
はwindowDidLoad()
呼び出されません(実行はブレークポイントで停止せず、ログは出力されません)。progressIndicator
それにもかかわらず、次のようなコードを使用して、アニメーション化しようとしてもアプリがクラッシュしないため、プロパティ/アウトレットは何らかの形で設定されています。
self.syncProgressWindowController.progressIndicator.startAnimation(self)
私は何が欠けていますか?