如何清除以前的ViewController的内存

时间:2012-04-03 14:10:01

标签: iphone ios xcode uiviewcontroller segue

我在进行MCQ游戏应用测试时遇到了这个问题。

我正在使用ARC&故事板自定义segue和[self performSegueWithIdentifier:@"VC" sender:self];ViewController1推送到ViewController2,但由于应用的自然性,很少会弹回ViewController1,从问题向前推进。经过多次推动,应用程序将变得非常缓慢。什么是解决问题的最佳方法?

自定义segue:

-(void)perform {
    UIViewController *sourceVC = (UIViewController *) self.sourceViewController;
    UIViewController *destinationVC = (UIViewController *) self.destinationViewController;

    [UIView transitionWithView:sourceVC.navigationController.view duration:0.5
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{
                        [sourceVC.navigationController pushViewController:destinationVC animated:NO];
                                           }
                    completion:^(BOOL  completed)
                    {     

                        //[sourceVC.navigationController pushViewController:destinationVC animated:NO];
                    }                      
                    ];



}

2 个答案:

答案 0 :(得分:1)

我怀疑有一个强大的参考周期。运行Leaks以确保在推送新的视图控制器之后没有强引用。

答案 1 :(得分:1)

我根据我的视图控制器名称将自定义segue从push更改为pop,并且它可以工作:)

-(void)perform {
    UIViewController *sourceVC = (UIViewController *) self.sourceViewController;
    //UIViewController *destinationVC = (UIViewController *) self.destinationViewController;

    NSInteger index = -1;
    NSArray* arr = [[NSArray alloc] initWithArray:sourceVC.navigationController.viewControllers];
    for(int i=0 ; i<[arr count] ; i++)
    {
        if([[arr objectAtIndex:i] isKindOfClass:NSClassFromString(@"mainViewController")])
        {
            index = i;
        }       
    }    

    [UIView transitionWithView:sourceVC.navigationController.view duration:0.5
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{

                        [sourceVC.navigationController popToViewController:[arr objectAtIndex:index] animated:NO];

                    }
                    completion:^(BOOL  completed)
     {     

         //[sourceVC.navigationController pushViewController:destinationVC animated:NO];
     }                      
     ];



}