Rinto Andrews Rinto Andrews - 2 months ago 11
iOS Question

How to Remove Last Added View Controller From Container

How to Remove Last Added View Controller From Container

I have used this code to remove last added view container

UIViewController *vc = [self.childViewControllers lastObject];
[vc.view removeFromSuperview];
[vc removeFromParentViewController];

[self.ctr addSubview:news.view];

Answer

First Call Method willMoveToParentViewController:nil

Then Call Remove From Super View

[vc willMoveToParentViewController:nil]; 

[vc.view removeFromSuperview];