nsviewcontroller

Handle close event of the window in Swift

白昼怎懂夜的黑 提交于 2019-12-05 06:03:16
How to handle close event of the window using swift, for example, to ask "Are you sure you want to close the form?" The form will be closed in the case "yes" and not closed in the case "no". Showing message box is not a problem for me. viewWillDisappear() works for minimizing also, but I need only close event. Thanks. Thomas Alvarez Like said above, you should make the ViewController an NSWindowDelegate , but you should handle windowWillClose , not windowShouldClose . windowShouldClose is to determine if the window is able to close or not, not an event that the window is actually closing. I

Navigation between NSVIewController

主宰稳场 提交于 2019-12-05 02:32:49
问题 I am very new to MAC OSX app development. In my application I have three NSViewControllers, which are PracticeController, NoteController and QuestionController. I have to navigate to NoteViewController from PracticeController and QuestionController and comeback to the viewController from which NoteController has navigated. For example: when we navigate to NoteController from PracticeController, then when we tap on back button from NoteController I have to come to PracticeController, and when

How to handle keyboard events in subclass of NSViewController?

大憨熊 提交于 2019-12-05 02:24:32
问题 I am creating one cocoa application having wizard like structure. All dialogs are subclass of NSViewController. Currently I am not able get keyboard events such as keyDown and keyUp.. Please help me to solve this problem.... Thanks in advance.... 回答1: Override keyDown: and keyUp: method. -(void)keyUp:(NSEvent*)event -(void)keyDown:(NSEvent*)event and - (BOOL)acceptsFirstResponder { return YES; } In subclass of NSViewController you should refer Cocoa Event-Handling Guide . 回答2: If you are

OS X addsubview from xib in swift

眉间皱痕 提交于 2019-12-04 19:35:12
I'm trying to add a new sub view form a nib using swift for OS X. So far i've: created a new "Cocoa Application" added a new "Cocoa Class" called "TestSubView" as a subclass of NSViewController with a XIB file I want to add this subview to my main view when the application loads. in my ViewController ( the ViewController for the main window ) i have. import Cocoa class ViewController: NSViewController { override func viewDidLoad() { super.viewDidLoad() let newSubView = TestSubView(); self.view.addSubview(newSubView.view); } override var representedObject: AnyObject? { didSet { // Update the

How exactly does an NSView, an NSViewController, and MainMenu.xib fit together?

社会主义新天地 提交于 2019-12-04 15:18:16
I'm going to cut right to the chase: my application has grown quite a bit, and now I think it's time for me to do some tidying up. I want to separate some of my views from my MainMenu.xib file into their own Nib file. The part that's tripping me up is the whole "Interface Builder + My Code" thing. Here's what I've done so far: I've added a view controller proxy object: In the Identity inspector, I've added my view controller's class name to the Custom Class field. In the Attributes inspector, I've entered the name of the Nib I want to load up. I've connected the view controller object's view

NSWindowController/NSViewController “Presentation” setting in Storyboard

笑着哭i 提交于 2019-12-03 22:05:53
What exactly does the Presentation option(in Attribute Inspector) do in StoryBoard for Cocoa. It gives two options to select from Single Multiple P.S When googled the title, results are related to powerpoint presentation The presentation style affects "Show" segues. Possibly it affects other segues too, but I only tested a Show segue. I tested on OS X 10.10.5 (Yosemite) with Xcode 7.1.1. If a window controller's presentation style is "Multiple" (the default), then a Show segue to the window controller always loads a new instance of the window controller from the storyboard. This means that you

Navigation between NSVIewController

隐身守侯 提交于 2019-12-03 20:24:16
I am very new to MAC OSX app development. In my application I have three NSViewControllers, which are PracticeController, NoteController and QuestionController. I have to navigate to NoteViewController from PracticeController and QuestionController and comeback to the viewController from which NoteController has navigated. For example: when we navigate to NoteController from PracticeController, then when we tap on back button from NoteController I have to come to PracticeController, and when we navigate to NoteController from QuestionController, then when we tap on back button from

How to handle keyboard events in subclass of NSViewController?

↘锁芯ラ 提交于 2019-12-03 18:54:32
I am creating one cocoa application having wizard like structure. All dialogs are subclass of NSViewController. Currently I am not able get keyboard events such as keyDown and keyUp.. Please help me to solve this problem.... Thanks in advance.... Override keyDown: and keyUp: method. -(void)keyUp:(NSEvent*)event -(void)keyDown:(NSEvent*)event and - (BOOL)acceptsFirstResponder { return YES; } In subclass of NSViewController you should refer Cocoa Event-Handling Guide . If you are trying to simply get an event for escape, use this instead: override var acceptsFirstResponder: Bool { return true }

Swift + NSViewController background color (Mac App)

不羁岁月 提交于 2019-12-03 04:45:22
I am trying to change the background color of my View. The View Controller class is NSViewController type. How this can be done? In iOS UIKit ( UIViewController ) there is self.view.backgroundColor , but NSViewController doesn't have that. And second problem is how can I change the color of the applications Title Bar? I think the background color doesn't affect to that. Mac application, language Swift. XCode 6.1. I managed to change background color of main view. NSViewController does not have backgroundColor property indeed, so I used the layer property of NSView that belongs to

Add completion handler to presentViewControllerAsSheet(NSViewController)?

落花浮王杯 提交于 2019-12-02 05:45:11
问题 I am attempting to present a sheet configuration view ( AddSoundEffect ) for my main window/view controller (I'm using storyboards), and when the configuration view controller is dismissed, take the values entered in the AddSoundEffect view and pass that back to the main view. My current code in the main view controller: presentViewControllerAsSheet(self.storyboard!.instantiateControllerWithIdentifier("AddSoundEffect") as! AddSoundViewController And in the AddSoundViewController.swift file,