Pregunta

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?

¿Fue útil?

Solución

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;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top