loading NIB fails once outlets are connected

151 Views Asked by At

Final Edit: so, it seems that the problem is that at the time that the outlets were connected, the File's Owner was AttributesPanel. This meant that the connections were made to that abstract entity, not to the actual swift UIView subclass. When I changed the File's Owner back to NSObject, the error started up, because it now expected NSObject to have those outlets, and fun ensued. Deleting every connection in IB and reconnecting them with the File's owner as NSObject, and connecting directly to the class of the nib was needed.

You might think that there might be a sanity check at compile time to alert you to this. But you'd be wrong.

Edit: I'd framed this around the idea that the connection to outlets caused the problem, but having disconnected everything from all outlets, it also crashes.

I'm using a Nib-based approach because I have an app with a lot of small palettes/panels that have to appear and be removed while the app is in use. But once I connected up the outlets, after I got the first panel loading, I got this error:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x6000031f2a20> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key clearRenderAreaButton.'

This is the code that is called to instantiate the first of the dozen or so NIBs:

  func openAlert() {
        self.view.addSubview(attributesPanel)
        NSLayoutConstraint.activate([
            attributesPanel.leadingAnchor.constraint(equalTo: drawingRenderPanel.leadingAnchor, constant: 100),
            attributesPanel.bottomAnchor.constraint(equalTo: drawingRenderPanel.bottomAnchor, constant: -100),
            attributesPanel.widthAnchor.constraint(equalToConstant: 650),
            attributesPanel.heightAnchor.constraint(equalToConstant: 160)
        ])
    }

The definition of AttributesPanel is :

    private lazy var attributesPanel: AttributesPanel = {
        let view = AttributesPanel.instanceFromNib()
        view.translatesAutoresizingMaskIntoConstraints = false
        return view
    }()

And the Swift Code that defines the class is

import UIKit

class AttributesPanel: UIView {
    
    class func instanceFromNib() -> AttributesPanel {
        let view = UINib(nibName: "AttributesPanel", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! AttributesPanel
        return view
    }
    

    @IBOutlet weak var useStrokeSwitch: UISwitch?
    @IBOutlet weak var strokeWeightLabel: UILabel?
    @IBOutlet weak var strokeHevValField: UILabel?
    @IBOutlet weak var strokeColorWellView: UIView?
    @IBOutlet weak var strokeUseOpacitySwitch: UISwitch?
    @IBOutlet weak var strokeOpacityField: UILabel?

    @IBOutlet weak var useFillSwitch: UISwitch?
    @IBOutlet weak var fillColorWellView: UIView?
    @IBOutlet weak var fillHexValField: UILabel?
    @IBOutlet weak var fillUseOpacitySwitch: UISwitch?
    @IBOutlet weak var fillOpacityField: UILabel?

    @IBOutlet weak var currentRenderPathField: UILabel?
    @IBOutlet weak var setRenderAreaButton: UIButton?
    @IBOutlet weak var clearRenderAreaButton: UIButton?
    @IBOutlet weak var renderCurrentPathButton: UIButton?
}

which looks like this in IB, with all outlets connected

Here's the swift file for the NIB: enter image description here

Before connecting the outlets, this worked fine, with the constraints etc working as expected, and the NIB, which looks like this, was displaying as expected:

enter image description here

The connection between the file's owner and the swift file in place. It seems to lead to a mismatch between what the addingSubView expects, and what it gets, but afaics, and given the connections are made, I'm not sure what the problem is.

EDIT: Clarification from the first comment: Here's the configuration of the nib file's owner :

enter image description here

and here's the file's owner. Still crashing. Or is this what you meant?

enter image description here

Second Edit: if I trace here:

enter image description here

This provides a nil response. So there's a failure here, no? I would assume that the problem is that it's not finding the nib based on the name, but that doesn't make much sense to me, given that it worked fine before I connected the outlets. Doe this give anyone any ideas of where to look?

enter image description here

To think how many I ate of these as a kid.

enter image description here

1

There are 1 best solutions below

1
ChanOnly123 On

Maybe here you need to remove this connection

enter image description here