Created
October 1, 2012 13:37
-
-
Save odrobnik/3811844 to your computer and use it in GitHub Desktop.
Modally presenting a sheet/panel the UIKit style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSWindow+DTViewControllerPresenting.m | |
// DTFoundation | |
// | |
// Created by Oliver Drobnik on 10/1/12. | |
// Copyright (c) 2012 Cocoanetics. All rights reserved. | |
// | |
#import "objc/runtime.h" | |
#import "NSWindow+DTPanelControllerPresenting.h" | |
static char DTPresentedViewControllerKey; | |
@implementation NSWindow (DTViewControllerPresenting) | |
- (void)presentModalPanelController:(NSWindowController *)panelController | |
{ | |
NSWindowController *windowController = self.modalPanelController; | |
if (windowController) | |
{ | |
NSLog(@"Already presenting %@, cannot modally present another panel", NSStringFromClass([windowController class])); | |
return; | |
} | |
[NSApp beginSheet:panelController.window modalForWindow:self modalDelegate:nil didEndSelector:nil contextInfo:nil]; | |
// retain the panel view controller | |
objc_setAssociatedObject(self, &DTPresentedViewControllerKey, panelController, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | |
} | |
- (void)dismissModalPanelController | |
{ | |
NSWindowController *windowController = self.modalPanelController; | |
if (!windowController) | |
{ | |
return; | |
} | |
// slide out | |
[NSApp endSheet:windowController.window]; | |
[windowController.window close]; | |
// free the panel view controller | |
objc_setAssociatedObject(self, &DTPresentedViewControllerKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | |
} | |
- (NSWindowController *)modalPanelController | |
{ | |
return objc_getAssociatedObject(self, &DTPresentedViewControllerKey); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment