ios - Data is passed only once to child VC in container view -


i trying pass data container view contain 1 of several child view controllers depending on user state. passing data first time new vc instantiated, if close , reopen child vc, data doesn't passed through again. here action when button pressed:

@ibaction func onmapbuttonpressed(sender: uibutton) {       let latitude = double(selectedplace.latitude!)       let longitude = double(selectedplace.longitude!)       bringinsubview("mapviewscreen")       (childviewcontrollers[0] as! placemapdetailvc).latitude = latitude!       (childviewcontrollers[0] as! placemapdetailvc).longitude = longitude!       (childviewcontrollers[0] as! placemapdetailvc).placename = selectedplace["name"] as! string    } 

and helper methods:

func bringinsubview(name:string) {        newviewcontroller = self.storyboard?.instantiateviewcontrollerwithidentifier(name)       newviewcontroller!.view.translatesautoresizingmaskintoconstraints = false       self.addchildviewcontroller(self.newviewcontroller!)       self.addsubview(self.newviewcontroller!.view, toview: self.containerview)       view.bringsubviewtofront(containerview)       view.bringsubviewtofront(closesubviewbutton)        uiview.animatewithduration(0.3, animations: {          self.containerview.alpha = 1          }, completion: { finished in             // else needed in completion block?       })    }  func addsubview(subview:uiview, toview parentview:uiview) {       parentview.addsubview(subview)       var viewbindingsdict = [string: anyobject]()       viewbindingsdict["subview"] = subview     parentview.addconstraints(nslayoutconstraint.constraintswithvisualformat("h:|[subview]|",          options: [], metrics: nil, views: viewbindingsdict))       parentview.addconstraints(nslayoutconstraint.constraintswithvisualformat("v:|[subview]|",          options: [], metrics: nil, views: viewbindingsdict))    } 

and getting rid of child vc:

@ibaction func onclosebuttoninsubviewpressed(sender: uibutton) {       uiview.animatewithduration(0.3, animations: {          self.containerview.alpha = 0          self.view.sendsubviewtoback(self.closesubviewbutton)          },          completion: { finished in             self.view.sendsubviewtoback(self.containerview)              // clears out prior view there free memory             view in self.containerview.subviews {                view.removefromsuperview()             }       })    } 

any insight appreciated, thank you!!!

i see problem code. in func onmapbuttonpressed(sender: uibutton) assume position 0. works @ first time because there. after first time remove , re-add again in bringinsubview(name:string) position changed. should check it.

hope help!


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -