如何正确地从一个UIPageViewController的子视图控制器中移除它?

3

我有一个 UIPageViewController 的子类,里面包含了一堆 UIViewController 的子类。

如果在其中一个 UIViewController 的子类中,用户进行某些操作,我想要移除整个 UIPageViewController 系统,以便只显示最初添加的下层子视图。

我使用以下方式将 UIPageViewController 子类作为主视图控制器的子视图控制器添加:

ImageGalleryPageViewController *galleryPageViewController = [[ImageGalleryPageViewController alloc] initWithImagesAndCaptions:imagesAndCaptions];
[self addChildViewController:galleryPageViewController];
[self.view addSubview:galleryPageViewController.view];
[galleryPageViewController didMoveToParentViewController:self];

我想知道从内部 UIViewControllers 中移除它的最佳实践方法。

我的第一反应是这样做:

[self.imageGallery removeFromParentViewController];
[self.imageGallery.view removeFromSuperview];

在我的UIViewController子类中,我有一个引用到它所包含的UIPageViewController子类,然后我告诉UIPageViewController子类将其移除。

这样做可以吗?我担心如果我移除包含调用的UIViewControllerUIPageViewController,那么第二个removeFromSuperview调用可能不会被调用,因为视图已经被移除了。

是否最好在UIPageViewController子类上拥有一个专门的方法,执行以上两种方法?或者有其他更好的方式吗?

此外,为什么需要同时调用这两个方法呢?为什么removeFromParentViewController不会同时移除view?为什么需要甚至添加两个方法呢?

1个回答

0

我想发表评论,但是我的声望不够。:(

我建议你所说的:

在UIPageViewController子类上是否有一个专门的方法来执行上述两种方法会更好呢?

你可以很容易地使用NSNotification来实现这一点。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接