2016-09-29 1286 views
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

相关问题