Reputation: 189
I have a navigation controller that push some viewcontroller. It works fine, but I can't clear navigation controller stack and so i've got memory warning...
Here is what I want to do :
Viewcontroller 1 : HomeViewController
ViewController 2 : LandingPageViewController
ViewController 3 : DetailsInnovViewController
homeViewController -> Push -> landingPageViewController -> Push -> detailsPageViewController -> Push -> homeViewController
It works but I want a new homeViewController, not the old. Si it can be deleted from navigation controller.
Here is how I push homeViewController from detailsPageViewController with my navigationController :
- (void)pushHomeVC
{
[LoginModel incrementCountedInnov];
for (UIViewController* vc in self.viewControllers) {
if ([vc isKindOfClass:[DetailsInnovViewController class]]) {
DetailsInnovViewController* dpvc = (DetailsInnovViewController*)vc;
[dpvc bannerHide];
break;
}
}
for (UIViewController* vc in self.viewControllers) {
if ([vc isKindOfClass:[HomeViewController class]]) {
[self popToRootViewControllerAnimated:NO];
[self pushViewController:vc animated:YES];
break;
}
}
}
Thx for helping!
Upvotes: 1
Views: 3117
Reputation: 657
I know this is an old question but I have recently had a similar problem and found that this solution worked for me:
[navigationController pushViewController:viewController animated:YES];
[navigationController setViewControllers:@[navigationController.topViewController]];
Upvotes: 2
Reputation: 189
I've found how to do this :
- (void)pushHomeVC
{
[LoginModel incrementCountedInnov];
for (UIViewController* vc in self.viewControllers) {
if ([vc isKindOfClass:[DetailsInnovViewController class]]) {
DetailsInnovViewController* dpvc = (DetailsInnovViewController*)vc;
[dpvc bannerHide];
break;
}
}
HomeViewController* homeVC = (HomeViewController*)[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"home-vc"];
[self pushViewController:homeVC animated:YES];
}
And my pushViewController method :
- (void)pushViewController:(UIViewController*)viewController animated:(BOOL)animated
{
@synchronized(self) {
if (isTransitioning == YES) {
[futureViewControllers addObject:viewController];
} else {
isTransitioning = YES;
if (self.viewControllers.count > 6) {
[super popToRootViewControllerAnimated:NO];
}
[super pushViewController:viewController animated:(BOOL)animated];
}
}
}
Thx !
Upvotes: 0