2017-03-16 138 views
0

我已經以編程方式添加了pageviewController,如下所示。有用。但是,當我嘗試使用[self.pageViewController.view removeFromSuperview];刪除它時,它不會將其刪除。以編程方式刪除PageViewController

添加pageViewController

self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"]; 
self.pageViewController.dataSource = self; 
self.pageViewController.delegate = self; 
PageContentViewController *startingViewController = [self viewControllerAtIndex:0]; 
NSArray *viewControllers = @[startingViewController]; 
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; 
[self addChildViewController:self.pageViewController]; 
[self.view addSubview:self.pageViewController.view]; 
[self.pageViewController didMoveToParentViewController:self]; 

刪除pageViewController

[self.pageViewController.view removeFromSuperview]; 

回答

1

使用下面的步驟來刪除您pageViewController:有時祛瘀

[self.pageViewController willMoveToParentViewController:nil]; 
[self.pageViewController.view removeFromSuperview]; 
[self.pageViewController removeFromParentViewController]; 
+0

它有時不是。 – hotspring