0

I am creating a save panel with an accessoryView that contains a single checkbox. I can get it to work when I create the button using:

NSButton(checkboxWithTitle: "Check Me", target: self, action: #selector(checkBoxSelected))

But this gives me a warning that this particular NSButton initializer requires macOS 10.12 and I need to support 10.10.

Here's my savePanel setup:

@IBAction func save(_ sender: NSButton) {
    let savePanel = NSSavePanel()
    savePanel.accessoryView = accessoryView()
    savePanel.runModal()
}

And here's how I create my accessory view in Sierra

func accessoryView() -> NSView {
    let checkbox = NSButton(checkboxWithTitle: "Check Me", target: self, action: #selector(checkBoxSelected))
    let view = NSView(frame: NSRect(x: 0, y: 0, width: 400, height: 100))
    view.addSubview(checkbox)
    return view
}

But this doesn't work (the button doesn't appear)

func accessoryView() -> NSView {
    let checkbox = NSButton()
    checkbox.setButtonType(NSSwitchButton)
    checkbox.title = "Check Me"
    checkbox.state = 1
    checkbox.target = self
    checkbox.action = #selector(checkBoxSelected)

    let view = NSView(frame: NSRect(x: 0, y: 0, width: 400, height: 100))
    view.addSubview(checkbox)
    return view
}

1 Answer 1

0

Got it.

Need to use NSButton.init(frame:)

Thanks

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.