gpt4 book ai didi

swift - 如何删除最后一个实例化的ViewController并使最后一个TableViewController变为事件状态

转载 作者:行者123 更新时间:2023-11-30 12:30:55 25 4
gpt4 key购买 nike

我实例化了一个 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中的图片:

Picture in ImageView

现在我想删除 Pageviewcontroller 并点击按钮返回 Maintableview。这是点击按钮的代码。

self.willMove(toParentViewController: nil)
self.view.removeFromSuperview()
self.removeFromParentViewController()

图像已删除,Maintableviewcontroller 已显示,但未处于事件状态。当我显示 View UI 层次结构时,pageviewcontrollercontentview 位于前面。

View 层次结构:

viewhierarchy

如何删除它并返回 Maintableviewcontroller?

最佳答案

很简单,您将 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

关于swift - 如何删除最后一个实例化的ViewController并使最后一个TableViewController变为事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43568770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com