0

I have added viewcontrollers in following fashion:

in first viewController:

[self.view addsubview:secondViewcontroller.view];

Then in second viewController:

[self.view addsubview:thirdViewcontroller.view];

Then in third viewController:

[self.view addsubview:fourthViewcontroller.view];

Now i am in fouthViewcontroller and want to go back to firsiViewController using removeFromSuperview method.

How can we achieve this? Is there any other way to do this. I don't want to use UINavigationController.

halfer
  • 19,824
  • 17
  • 99
  • 186
DJB
  • 857
  • 7
  • 15

2 Answers2

0

Try the below code, it may work

NSArray * subviews = [self.view subviews];
    int cnt = [subviews count];
    for(int j=cnt-1; j >=0 ; --j )
    {
        UIView * sview = [subviews objectAtIndex:j];
        [sview removeFromSuperview];
    }
Sharme
  • 625
  • 4
  • 10
  • 28
0

In one row

[self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
invoodoo
  • 3,905
  • 1
  • 18
  • 16