2014-03-19 111 views
0

我有一個導航控制器,推一些viewcontroller。它工作正常,但我不能清晰的導航控制器棧,所以我已經得到了內存不足的警告......清除導航控制器堆棧時推ViewController

這是我想做的事:

Viewcontroller 1 : HomeViewController 
ViewController 2 : LandingPageViewController 
ViewController 3 : DetailsInnovViewController 

homeViewController -> Push -> landingPageViewController -> Push -> detailsPageViewController -> Push -> homeViewController 

它的工作原理,但我希望有一個新的homeViewController,不是舊的。它可以從導航控制器中刪除。

這裏是我推homeViewController從detailsPageViewController我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的幫助!

+0

可惜HomeViewController未設置爲根... – testoverblaireau

回答

0

我發現如何做到這一點:

- (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]; 
} 

而且我pushViewController方法:

- (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!

2

我知道這是一個老問題,但最近我有一個類似的問題,發現這個解決方案爲我工作:

[navigationController pushViewController:viewController animated:YES]; 
[navigationController setViewControllers:@[navigationController.topViewController]]; 
相關問題