0

Background:

I have 4 .XIB files which are initialized programmatically as Subviews to be called to the screen via the method self.view.addSubview(UIView).

    //Initialize Associate Degree Selection UIView and prepare contraints
    degreeAuditAssociatesView = instanceFromNib(XIBFilename: "degreeAuditAssociate")
    degreeAuditAssociatesView?.frame = self.view.bounds
    degreeAuditAssociatesView?.autoresizingMask = [UIViewAutoresizing.flexibleWidth,UIViewAutoresizing.flexibleHeight]
    loadSavedCheckboxes()

    //Initialize Associate Degree Selection Results UIView and prepare contraints
    degreeAuditAssociatesViewResults = instanceFromNib(XIBFilename: "degreeAuditAssociateResults")
    degreeAuditAssociatesViewResults?.frame = self.view.bounds
    degreeAuditAssociatesViewResults?.autoresizingMask = [UIViewAutoresizing.flexibleWidth,UIViewAutoresizing.flexibleHeight]

    //Initialize Bachelors Degree Selection UIView and prepare contraints
    degreeAuditBachelorsView = instanceFromNib(XIBFilename: "degreeAuditBachelors")
    degreeAuditBachelorsView?.frame = self.view.bounds
    degreeAuditBachelorsView?.autoresizingMask = [UIViewAutoresizing.flexibleWidth,UIViewAutoresizing.flexibleHeight]
    loadSavedCheckboxes()

    //Initialize Bachelors Degree Selection Results UIView and prepare contraints
    degreeAuditBachelorsViewResults = instanceFromNib(XIBFilename: "degreeAuditBachelorsResults")
    degreeAuditBachelorsViewResults?.frame = self.view.bounds
    degreeAuditBachelorsViewResults?.autoresizingMask = [UIViewAutoresizing.flexibleWidth,UIViewAutoresizing.flexibleHeight]

When I call self.view.addSubview(degreeAuditBachelorsViewResults!), the view properly displays this XIB UIView and populates all the Text-boxes and display elements accordingly.

Problem: When I call self.view.addSubview(degreeAuditAssociatesViewResults!) ( Second Block of Code), the view displays this XIB UIView but WITHOUT populating any of the data in the text-boxes.

What's Weird When I remove the code and never initialize the fourth UIView (Fourth Block of Code)(degreeAuditBachelorsViewResults), the degreeAuditAssociateResults UIView loads with no problem.

When I move around the blocks of code, either (Block 2) or (Block 4) are not displayed with all text elements populated with information. I have a feeling it has something to do with addSubview(UIView) method and not accepting any information.

Please Help, I have run out of options.

  • What's going on in `loadSavedCheckboxes()`? – DonMag Apr 18 '18 at 18:34
  • That Function is setting a UI button to be enabled if UserDefaults.standard keys are set to be true. – Cristian325 Apr 18 '18 at 18:38
  • OK - a little confusing then... Are you loading all four of these at the same time? So they overlap each other (they all have their frame set to view.bounds)? Where is the code that is "populating the Text-boxes and display elements"? – DonMag Apr 18 '18 at 19:30
  • I just had a lightbulb moment. It lid up when you said it had to do something with the checboxes. After further debugging, I found the problem. In xcode, the last view that is initiliazed assigns the reference outlets. It looks like both views were referencing the same outlets but the last view was the one conencting the outlets and disconnecting the other views. That is why only the Last Block of code was populating and no the second one. This has been resolved. THANKS DonMag! – Cristian325 Apr 18 '18 at 19:34

1 Answers1

0

This is for future reference of this problem. If two views have the same reference outlet and are being programmatically initialized from XIB file. The last initialized UI view will have the reference outlets connected. Each view should have their separate outlet referenced when possible.