0

是否可以在iOS中回收/強制銷燬UIViewController問:如何強制銷燬iOS中的視圖控制器?

我用這github project得到一個定製UIViewControllerTransition

這裏是程序的流程:

  • vc1禮物給nav到的rootVcvc2
  • vc2有是UIButton。點擊後,vc2NavigatioCcontroller將被解僱。

但問題是,vc2不是由OS回收,所以當我進展爲vc1,然後呈現給nav(這rootVcvc2),vc2不調用viewDidLoad方法。

不知道問題出在哪裏。有沒有辦法讓我點擊vc2UIButton,強制銷燬navvc2?這樣,當我再次出現到nav時,vc2viewDidload將再次被調用。

代碼

vc1

LMLQQSearchSelectViewController *search_vc = [[LMLQQSearchSelectViewController alloc] initWithNibName:@"LMLQQSearchSelectViewController" bundle:nil]; 
search_vc.fromController = @"KnowledgeViewController"; 
search_vc.pre_type = @"ENCYCLOPEDIACOL"; 
LMLQQSearchNavController *nav = [[LMLQQSearchNavController alloc] initWithRootViewController:search_vc]; 
nav.navigationBarHidden = YES; 


__weak typeof(self) weakSelf = self; 

_search_header.block = ^(){ 

    weakSelf.transition = [[HYBEaseInOutTransition alloc] initWithPresented:^(UIViewController *presented, UIViewController *presenting, UIViewController *source, HYBBaseTransition *transition) { 
     HYBEaseInOutTransition *modal = (HYBEaseInOutTransition *)transition; 

     // If you don't specify, it will use default value 
     // Default is NO, if set to YES, it will use spring animation. 
     modal.animatedWithSpring = NO; 
    } dismissed:^(UIViewController *dismissed, HYBBaseTransition *transition) { 
     // do nothing 
    }]; 

    nav.transitioningDelegate = weakSelf.transition; 
    [weakSelf presentViewController:nav animated:YES completion:NULL]; 

}; 

回答

0

nav被駁回,你必須掛到它的引用,以便以後可以重新顯示。並且由於nav持有對vc2的引用,因此當您重新顯示nav時,會再次返回相同的實例。

您有兩種選擇。其一,你可以在解散後發佈你對nav的引用,然後發佈vc2。二,你可以將你想運行的代碼vc2每次從viewDidLoad出現到viewDidAppear

+0

我想到了'option 2',它會在我的項目中造成一些麻煩,我會在選項1中進行測試,你的意思是在方法中:'[self.navigationController dismissViewControllerAnimated:YES completion:^ { //重置root vc? }];' – aircraft

相關問題