0

I've read this document. Seen this SO question (amongst others). And had a look at this tutorial. But for the life of me I cannot get my custom storyboard segue to work. I'm using the code found in this SO answer to bring on new views and their controllers.

Basically, the user is presented with 5 buttons in the initial view and clicking any one will cause another view to slide in from the left. All works fine, any NSButtons that are placed on the new views receive clicks and do what they're supposed to. However, text fields are completely unaccessible: you can select any text within but not overwrite.

I'm assuming that I haven't injected the new view/view controler into the responder chain correctly (but then why do the buttons work and the text fields not?).

Judicious use of

self.resignFirstResponder()

and

newViewController.becomeFirstResponder()

always return true. I've placed them in the various initial lifecycle functions of the new views as well as in the actual custom NSViewControllerPresentationAnimator at the end of the animation.

If the segue is a preset sheet, modal, popover or whatever then the new view receives all actions/typing just fine. So it's definitely my code.

I know it's not good form but I'm going mad: can someone please provide a step by step example using Swift?

[EDIT] Arghhhh! It seems to be that because I had the 'Title Bar' unchecked on my app window then it refused to take first responder. Shame, I quite liked the clean window with no title look....

Todd
  • 1,770
  • 1
  • 17
  • 42
  • Are the text fields editable? If you can select the text, they respond to mouse events and are in the responder chain. – Willeke Jun 16 '17 at 13:37
  • That's the weird bit: no, they're not. Selectable but not editable. The view also has a lighter colour on it's background from when it's fully operable after a preset segue transition. – Todd Jun 16 '17 at 13:43
  • [Not being able to edit NSTextField on NSPopover even though Editable behavior is set](https://stackoverflow.com/q/7214273/4244136) – Willeke Jun 16 '17 at 14:10

1 Answers1

0

In my case I wanted there to be no Title Bar to the App window. When the Title Bar option is unchecked in IB Attributes section of the storyboard window then you need to sub-class NSWindow and override canBecomeMain and canBecomeKey:

import Cocoa

class BTVWindow: NSWindow {

    override var canBecomeKey: Bool{
        get {
            return true
        }
    }

    override var canBecomeMain: Bool{
        get {
            return true
        }
    }
}
Todd
  • 1,770
  • 1
  • 17
  • 42