Reputation: 213
I am using NSTitlebarAccessoryViewController
objects in my Cocoa
app. I have implemented state restoration for the NSWindow
and it appears to be working correctly as previous NSWindow
objects along with their size and position are correctly restored.
I have also implemented state restoration in NSTitlebarAccessoryViewController
subclasses by overriding encodeRestorableState(with:backgroundQueue:)
and restoreState(with:)
method. It works fine but I am having trouble with the timing.
My NSTitlebarAccessoryViewController
objects drive the detail NSViewController
, similar to how a sidebar does the same thing using delegation design pattern.
I managed a collection of NSTitlebarAccessoryViewController
objects in the container NSViewController
of the detail NSViewController
rather than in the NSWindowController
subclass.
My NSTitlebarAccessoryViewController
objects contain a collection of NSButton
controls so that is why I am using state restoration to restore the state of the NSButton
, e.g. which NSButton
state is switched on and which NSButton
are switched off. Only one NSButton
can be switched on.
The problem is by the time I have restored the state of the NSButton
controls in the NSTitlebarAccessoryViewController
object, the container NSViewController
is using the default fallback NSButton
, which is the first NSButton
in the NSTitlebarAccessoryViewController
object.
How can I make the container NSViewController
use the restored state of NSTitlebarAccessoryViewController
instead of the first NSButton
as if the app was launched the very first time? Because the detail NSViewController
doesn't not reflect the NSTitlebarAccessoryViewController
object selection.
Using print(_:separator:terminator:)
statements in various places in NSWindowController
, NSSplitViewController
, NSViewController
and NSTitlebarAccessoryViewController
subclasses, I noticed that NSTitlebarAccessoryViewController
objects are typically restored last whereas my NSViewController
business logic starts working earlier. Maybe that is why it will not be restored in time. Is there a solution? I tried moving the NSTitlebarAccessoryViewController
objects management in NSWindowController
subclass and it didn't help.
Upvotes: 0
Views: 13