Question

On OS X 10.9 there is a new block-based method for sheet presentation:

    [window beginSheet:[myWindowController window] 
        completionHandler:^(NSModalResponse returnCode) {
            NSLog(@"done");
    }
    ];

The problem is that myWindowController is deallocated immediately if it isn't referenced in the completion block. This causes a crash when its window is dismissed. When using ARC, how can I ensure the sheet's window controller lives through the modal session?

Was it helpful?

Solution

I originally did this as a comment but I'll make this as an answer:

You should assign "myWindowController" to a strong property in whatever object (NSWindowController or whatever) that brings up the sheet.

E.G., use

@property (strong) NSWindowController *mySpecialSheet;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top