1

I have an app and I want to have separate windows. What's the best way to load them all on startup? I think I want to have the main window load the others. Here's what I got now, doesn't work..

I subclassed the main window controller, and am trying to load another storyboards window. (I can keep in it in the main storyboard if needed).

class MainWindow: NSWindowController {

    override init() {
    super.init()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        let sb = NSStoryboard(name: "SecondStoryboard", bundle: nil)
        let win = sb?.instantiateControllerWithIdentifier("WindowTwo") as NSWindowController
        win.showWindow(nil)

    }


}

In the end, I need to be able to pass data between the controllers.

JoeBayLD
  • 939
  • 2
  • 10
  • 25
  • This isn't really an answer. If you suggest another method, give an example and explain in detail how to do it. I'm not entirely sure what you mean. Make it persistent? What's so bad about storyboards? I like them and how they work with constraints. – JoeBayLD Feb 26 '15 at 06:31

2 Answers2

1
import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!
    @IBOutlet weak var preferencesPanel: NSPanel!
    @IBOutlet weak var transparentCheck: NSButton!

    var oldColor:NSColor?
    func applicationDidFinishLaunching(aNotification: NSNotification) {
        // Insert code here to initialize your application
        oldColor = window.backgroundColor
        window.level = screenSaverLevel
        preferencesPanel.level = maximumWindowLevelKey
    }

    func applicationWillTerminate(aNotification: NSNotification) {
        // Insert code here to tear down your application
    }
    @IBAction func transparentWindowAction(sender: AnyObject) {

        window.opaque = transparentCheck.state == NSOffState
        window.backgroundColor = transparentCheck.state == NSOffState ? oldColor : NSColor(calibratedHue: 0, saturation: 0, brightness: 0, alpha: 0.7)
    }


}

enter image description here

enter image description here

enter image description here

windowsSampleProject

Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
  • Thats all you need without storyboards – Leo Dabus Feb 26 '15 at 07:03
  • I've already connected the preferences panel window to my application menu and with this outlet I control it together with all other windows I might need – Leo Dabus Feb 26 '15 at 07:04
  • You don't want the preferences to show at login. Just deselect visible at launch – Leo Dabus Feb 26 '15 at 07:06
  • After looking at this, I need to use a storyboard. I already have it built it, and personally am not a fan of xibs. I need to know a way to display multiple storyboards in Xcode. – JoeBayLD Mar 03 '15 at 19:28
0

Create id for all that you need to be loaded from start. Load your controllers using their id.

This code work for me. It is based on this post: How does OS X load a storyboard based app, and how does it do window management?

lazy var preferenceWindowController: TYPEPreferenceWindowController? =
    {
        let theStoryboard :NSStoryboard? = NSStoryboard(name: "Main", bundle: nil)
        var thePreferenceWindowController  = theStoryboard?.instantiateControllerWithIdentifier("PreferenceWindowController") as TYPEPreferenceWindowController?
        return thePreferenceWindowController
    }()



 @IBAction func showPreferencePanel(sender: AnyObject) {
        println("showPreferencePanel")
        preferenceWindowController?.showWindow(self)


    }
Community
  • 1
  • 1