• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Cocoa UI preservation - simple example
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cocoa UI preservation - simple example


  • Subject: Cocoa UI preservation - simple example
  • From: Dragan Milić <email@hidden>
  • Date: Tue, 05 Jul 2016 14:28:31 +0200

I’m trying to make usage of Cocoa UI preservation API, but it seems I got stuck at the very beginning and even after almost two hours of trying to figure out what I’m doing wrong, there’s no progress at all. I’m sensing I’m missing something obvious, but I don’t know what that would be.

Anyhow, I’ve created a very simple single window application, with (main) window, controlled by its accompanying  (main) window controller. The controller implementation is fairly simple:


@implementation MainWindowController

- (instancetype)init
{
    self = [super initWithWindowNibName:@"MainWindow" owner:self];

    if (self)
    {
        // Some code here.
    }

    return self;
}

- (void)windowDidLoad
{
    [super windowDidLoad];
    // Some code here.
}

@end


The application delegate is responsible for preservation and it’s implemented exactly like in many examples I’ve found online, as well as in Apple documentation:


@interface AppDelegate ()
@property (nonatomic, strong) NSWindowController *mainWindowController;
@end

@implementation AppDelegate

+ (void)restoreWindowWithIdentifier:(NSString *)anIdentifier
                              state:(NSCoder *)aState
                  completionHandler:(void (^)(NSWindow *, NSError *))aCompletionHandler
{
    NSWindow *window;

    if ([anIdentifier isEqualToString:@"main window"])
    {
        AppDelegate *delegate = [NSApp delegate];
        window = [[delegate mainWindowController] window];
    }

    aCompletionHandler(window, nil);
}

- (NSWindowController *)mainWindowController
{
    if (!_mainWindowController)
    {
        _mainWindowController = [[MainWindowController alloc] init];

        [[_mainWindowController window] setRestorable:YES];
        [[_mainWindowController window] setIdentifier:@"main window"];
        [[_mainWindowController window] setRestorationClass:[self class]];
    }

    return _mainWindowController;
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [[self mainWindowController] showWindow:self];
}

- (void)applicationWillTerminate:(NSNotification *)aNotification
{

}

@end


The window itself (loaded from the nib file “MainWindow.xib” contains just one tab view, with four tabs.

When I start the application, the window appears just like it was designed in the nib file. Then I resize it and change its position on the screen, as well as change selected tab of the tab view. Quitting and relaunching the application shows the window just like it was designed in the nib files, not UI changes were preserved. The    method never gets executed. Additionally, I don’t see any preserved data for the application being saved in the “~/Library/Saved Application State/” folder.

Is the code above enough to make this simple UI preservation work, or do I need to do something more (and what)?

Thanks in advance.
-- Dragan
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Prev by Date: Property synthesis trouble - 32 vs 64 bit builds
  • Next by Date: Prioritize my own app's disk access
  • Previous by thread: Re: Property synthesis trouble - 32 vs 64 bit builds
  • Next by thread: Prioritize my own app's disk access
  • Index(es):
    • Date
    • Thread