Reputation:
Why are the methods moveLeft() and moveRight() being called, I have turned off the first responder ability for the window controller? I haven't added any code in elsewhere, so I'm obviously missing something somewhere...
In the end I do want to accept events, but if I 'enable' them here and deal with overriding keyEvent(), it causes it to be handled twice and a choice being made twice.
import Cocoa
enum UserChoice {
case Left, Right
}
class MainWindowController: NSWindowController {
override func windowDidLoad() {
super.windowDidLoad()
}
override var windowNibName: String? {
return "MainWindowController"
}
override var acceptsFirstResponder: Bool {
return false
}
override func moveLeft(sender: AnyObject?) {
chooseImage(UserChoice.Left)
}
override func moveRight(sender: AnyObject?) {
chooseImage(UserChoice.Right)
}
func chooseImage(choice: UserChoice) {
print("choice made")
}
}
The only other file I have is AppDelegate.swift:
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var mainWindowController: MainWindowController!
func applicationDidFinishLaunching(notification: NSNotification) {
mainWindowController = MainWindowController()
mainWindowController.showWindow(self)
}
}
Any comments on my code are welcome too, I'm new to Swift/Cocoa so...
Upvotes: 0
Views: 435
Reputation: 22707
When your controller refuses to be first responder, it's still a responder, just not the first one. Another responder such as the window or a view within it can choose to pass the buck back up the responder chain.
I'm not clear on why you implemented moveLeft
and moveRight
if you don't want to handle them.
Upvotes: 3