문제

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?

도움이 되었습니까?

해결책

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top