ios - How to remove the ChildViewController from Parent View Controller in Swift 3 -
i developing ios application. have added uiviewcontroller in view pager. want reinitialize when language changed. here want remove child uiviewcontroller uiviewpager , again add uiviewcontroller viewpager. how can that?
sample code
viewpager = viewpagercontroller() viewpager.options = options viewpager.datasource = self viewpager.delegate = self self.addchildviewcontroller(viewpager)
swift 3.1
xcode 8.3.3
after long search remove view controllers viewpager. did in following way.
if self.childviewcontrollers.count > 0{ let viewcontrollers:[uiviewcontroller] = self.childviewcontrollers viewcontoller in viewcontrollers{ viewcontoller.willmove(toparentviewcontroller: nil) viewcontoller.view.removefromsuperview() viewcontoller.removefromparentviewcontroller() } }
here self , current uiviewcontroller has view pager. need remove childview controllers view pager. so, list of view controllers current uiviewcontroller. removed parent view.
Comments
Post a Comment