问:如何强制销毁iOS中的viewcontroller?

时间:2016-09-29 03:27:36

标签: ios objective-c memory controller presentmodalviewcontroller

是否可以在iOS中回收/强制销毁UIViewController

我正在使用此github project获取自定义UIViewControllerTransition

以下是该计划的流程:

  • vc1nav rootVc vc2
  • vc2呈现
  • UIButton中有一个vc2。点击后,NavigatioCcontroller' vc2将被解雇。

但问题是操作系统不会回收vc1,因此当我转到nav时,会转到rootVcvc2为{{1} }}),vc2不会调用viewDidLoad方法。

不确定问题出在哪里。有没有办法让我点击vc2' UIButton时,强制销毁navvc2?这样,当我重新呈现给nav时,vc2 viewDidload将再次被调用。

代码

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

};

1 个答案:

答案 0 :(得分:0)

nav被解雇时,您必须挂在它的引用上,以便以后可以重新显示它。由于nav持有对vc2的引用,因此当您重新显示nav时,会再次获得相同的实例。

您有两种选择。其一,您可以在nav被解雇后释放您对vc2的引用,然后也会释放vc2。第二,您可以在viewDidLoad viewDidAppear symbol var symbol = d3.symbol(); 出现path后,将要运行的代码移动。