NSSlider object crashes code when it's moved on view

51 Views Asked by At

I've created an NSViewController with corresponding XIB in IB. FWIW, I have the following window/view hierarchy:

class RxDemoController: NSWindowController {

    @IBOutlet weak var statusPaneView: NSView!
    @IBOutlet weak var annunciatorPaneView: NSView!
    @IBOutlet weak var trigaStatusPaneView: NSView!
    @IBOutlet weak var rxTabView: NSView!


    override var windowNibName  :String? { return "RxDemoController" }


    override func windowDidLoad() {
        super.windowDidLoad()

        let statusPaneViewController = StatusPaneViewController()
        statusPaneView.addSubview( statusPaneViewController.view )

        let annunciatorPaneViewController = AnnunciatorPaneViewController()
        annunciatorPaneView.addSubview( annunciatorPaneViewController.view )

        let trigaStatusPaneController = TrigaStatusPaneController()
        trigaStatusPaneView.addSubview( trigaStatusPaneController.view )

        let rxTabController = RxTabController()
        rxTabView.addSubview( rxTabController.view )

    }

}

We can ignore the statesPaneViewController, annunciatorPaneViewController, and trigaStatusPaneController as they are all working properly. The rxTabController object is a tab view, defined in RXTabController.swift as follows:

class RxTabController: NSTabViewController {

    @IBOutlet weak var rxDisplay1TabView: NSView!

    override var nibName :String? { return "RxTabController" }
    override func viewDidLoad() {
        super.viewDidLoad()

        let rxDisplay1ViewController     = RxDisplay1()
        rxDisplay1TabView.addSubview( rxDisplay1ViewController.view )
    }

RxDisplay1.xib currently contains two objects: a bar graph object (custom component: LinearBarGraph_t which has been working fine in other projects and works fine on the view controller for the first tab), the second object is an NSSlider. The NSSlider is giving me problems. Here's the code for RxDisplay1:

class RxDisplay1: NSViewController {

    @IBOutlet weak var linearPwrBG: LinearBarGraph_t!

    override func viewDidLoad() {
        super.viewDidLoad()

        linearPwrBG.pctInRange = 50
    }

    @IBAction func linearPwrSlider(sender: NSSlider) {
    }

}

I have right-dragged from the bar graph object to produce the @IBOutlet weak var linearPwrBG: LinearBarGraph_t! outlet; note that in viewDidLoad I set the pctInRange field to 50. This works fine when the app starts up (the bar graph is filled to the 50% mark).

The problem is with the slider. I've right dragged from the slider to the RxDisplay1 class to produce the linearPwrSlider action function. The connection seems to be fine (little filled dot next to the function declaration and right-clicking on the slider shows the action going to this function).

When I run the code, the display (and tab) properly appear. My bar graph shows 50% power. However, the moment I touch the slider with the mouse the system crashes. I get a break in AppDelegate complaining about "Bad Access".

I've used sliders all the time in past projects. However, this is the first time I've used a tabbed controller so I suspect there is something wrong with the way I've connected the tabbed controller to the rest of the system.

0

There are 0 best solutions below