Skip to content

Instantly share code, notes, and snippets.

@udondan
Last active April 21, 2017 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save udondan/1960409b8f17c0d3d6ff to your computer and use it in GitHub Desktop.
Save udondan/1960409b8f17c0d3d6ff to your computer and use it in GitHub Desktop.
Swift controller for a modal window / sheet; see http://acapio.de/xcode/2014/07/12/swift_set_modal_window.html
import Cocoa
class MyModalWindowController: NSWindowController {
var mainW: NSWindow = NSWindow()
override init() {
super.init()
}
override init(window: NSWindow!) {
super.init(window: window)
//Initialization code here.
}
required init?(coder: (NSCoder!)){
super.init(coder: coder);
}
override func windowDidLoad() {
super.windowDidLoad()
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}
//method called to display the modal window
func beginSheet(mainWindow: NSWindow){
self.mainW = mainWindow
NSApp.beginSheet(self.window!, modalForWindow: mainWindow, modalDelegate: self, didEndSelector:nil, contextInfo: nil)
}
//method called, when "Close" - Button clicked
@IBAction func btnClicked(sender: AnyObject) {
self.endSheet();
}
//method called to slide out the modal window
func endSheet(){
NSApp.endSheet(self.window!)
self.window!.orderOut(mainW)
}
}
@Alotabi1
Copy link

Alotabi1 commented Feb 6, 2017

#include
#inclode
#using namespace std;
int main ()

@1Mr-Styler
Copy link

Nice. You should update it to use NSWindow beginsheet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment