我实例化了一个PageViewController并显示图像。
let storyboard = UIStoryboard(name: "Main", bundle: nil)
self.pageViewController = storyboard.instantiateViewController(withIdentifier: "articlePageViewController") as! UIPageViewController
self.pageViewController.dataSource = self
let initialContenViewController = self.pageTutorialAtIndex(0) as ArticleImageViewController
self.pageViewController.setViewControllers([initialContenViewController], direction: UIPageViewControllerNavigationDirection.forward, animated: true, completion: nil)
self.pageViewController.view.frame = CGRect(x: 0, y: 0, width: Int(self.view.frame.width), height: Int(self.view.frame.height))
self.pageViewController.view.center = self.mainView.center
self.pageViewController.view.tag = 100
self.addChildViewController(self.pageViewController)
self.view.addSubview(self.pageViewController.view)
self.pageViewController.didMove(toParentViewController: self)
ImageView中的图片:
现在我要删除Pageviewcontroller并点击按钮返回Maintableview。这是点击按钮的代码。
self.willMove(toParentViewController: nil)
self.view.removeFromSuperview()
self.removeFromParentViewController()
删除图像并显示Maintableviewcontroller但未激活。当我显示视图UI层次结构时,pageviewcontrollercontentview位于前面。
viewhierarchy:
如何删除它并返回Maintableviewcontroller?
答案 0 :(得分:0)
很简单,你将pageviewcontroller添加为:
self.addChildViewController(self.pageViewController) //===> Step 1
self.view.addSubview(self.pageViewController.view) //additional step required while adding
self.pageViewController.didMove(toParentViewController: self) //===> Step 2
尝试:
[self.pageViewController removeFromParentViewController]; //===> Reverse of Step 1
[self.pageViewController didMoveToParentViewController:self];//===> Reverse of Step 2
来自PageViewController的调用如下:
[self removeFromParentViewController]; //===> Reverse of Step 1
[self didMoveToParentViewController:self.parentViewController];//===> Reverse of Step 2