Unable to Modify View Elements when Adding a SubView

时间:2018-04-18 18:04:37

标签: ios xcode swift4.1

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.

1 个答案:

答案 0 :(得分:0)

这是为了将来参考这个问题。如果两个视图具有相同的参考插座,并且正在以编程方式从XIB文件初始化。最后初始化的UI视图将连接参考插座。每个视图应尽可能引用其独立的插座。