ios - How to find and replace a subview from UIScrollView -


i have scrollview have added 4 subviews @ viewdidload, during app usage on event want replace 1 of subview new view.

i trying add tag subview , find , replace tag seems not found. not able find correct way replace view

let subviews = self.scrollview.subviews subview in subviews{     if subview.tag == 1000 {         let tempview = subview         tempview = newview     } } 

i sure above code isn't right , here code never enters inside 'if' , when see subviews in debug area dont see tag well.

code viewdidload

        let storyboard = uistoryboard(name: "main", bundle: nil)         self.overleftvc = storyboard.instantiateviewcontroller(withidentifier: "settingviewcontroller")         self.leftvc = storyboard.instantiateviewcontroller(withidentifier: "giftcardlistviewcontroller")         self.middlevc = storyboard.instantiateviewcontroller(withidentifier: "redeemviewcontroller")         self.rightvc = storyboard.instantiateviewcontroller(withidentifier: "homeviewcontroller")         self.overrightvc = storyboard.instantiateviewcontroller(withidentifier: "ticketlistviewcontroller")          let isshowbotview = self.config.getvalue("issystemgenerated", fromstore: "settings") as! bool          if isshowbotview == true {             self.nextofoverrightvc = storyboard.instantiateviewcontroller(withidentifier: "chatviewcontroller")         }         else {             self.nextofoverrightvc = storyboard.instantiateviewcontroller(withidentifier: "tilemainviewcontroller")         }          self.nextofoverrightvc.view.tag = 1000                addchildviewcontroller(overleftvc)             addchildviewcontroller(leftvc)             addchildviewcontroller(middlevertscrollvc)             addchildviewcontroller(nextofoverrightvc)           //  addchildviewcontroller(tilemainrightvc)              scrollview.addsubview(overleftvc.view)             scrollview.addsubview(leftvc.view)             scrollview.addsubview(middlevertscrollvc.view)             scrollview.addsubview(nextofoverrightvc.view) 

save subview's frame in variable , remove subview , insert new subview @ frame

for subview in subviews{ if subview.tag == 1000 {     self.frameofviewtobereplaced = subview.frame     subview.removefromsuperview()      }  }  let newview = uiview(frame : self.frameofviewtobereplaced) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -