Reputation: 491
I got a ViewController where I add many childs on like this:
[self addChildViewController:myViewController];
After this I want to remove some of the childs dependent on where I am in my program to free up memory. So I was thinking of something like this:
[self.childViewControllers objectAtIndex:1]
and then use removeFromParentViewController
. But how can I provide this code on objectAtIndex?
I also tried: [self.childViewControllers objectAtIndex:1] = nil;
But this doesn't work, I get the error that the expression is not assignable.
Upvotes: 1
Views: 860
Reputation: 89509
You can get an array of view controllers by doing "[self.navigationController viewControllers]
".
Then you can get any one of them via "objectAtIndex:
" on that array.
When you get any one of them, you can call removeFromParentViewController
" on that view controller.
However, I wouldn't do what you're trying to do. This is going to likely to confuse the heck out of your users, who were navigating through your app thinking they came from one specific view controller, only now when they back up they're going back to somewhere unexpected.
Upvotes: 1