2013-11-25 30 views
0

我有3 UIViewcontroller A(根視圖控制器),B和C.我使用下面的代碼來推A視圖控制器B從A.Do相同推動Viewcontrolller C從A.我怎樣才能釋放nsmuatablearray iOS中的後視圖控制器

BViewController *statusView = [[BViewController alloc]initWithNibName:@"BViewController" bundle:nil]; 
UINavigationController *objNavigationController=[[[UINavigationController alloc]initWithRootViewController:statusView]autorelease]; 
[self presentViewController:objNavigationController animated:NO completion:nil]; 
[statusView release]; 

我創建的自定義後退按鈕和下面的代碼用於備份的ViewController答:

AViewController *chooseview = [[AViewController alloc] initWithNibName:@AController" bundle:nil]; 
} 
UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:chooseview]; 
[self.navigationController presentViewController:navC animated:NO completion:nil]; 
[chooseview release]; 

而現在,我想釋放許多陣列中的ViewController B和C我點擊後退按鈕後。我怎樣才能做到這一點?我嘗試使用[array release];但我返回viewcontroller B後,我的應用程序崩潰。感謝您的建議。

+0

? – trojanfoe

+0

@trojanfoe:不,我不使用ARC。 –

+0

把[數組發佈];在viewDidDisappear方法中,你要釋放這個數組 – Greg

回答

0

你可以嘗試把這樣的事情

if ([array count] > 0) { 
    [array release]; 
} 

array = [[NSMutableArray alloc] init]; 

在你的根視圖控制器的viewWillAppear

+0

爲什麼'if([array count]> 0)'測試? – trojanfoe

+0

它是一種「你的數組不是空的/它存在」,所以你可以釋放smth) – Konstantin

+0

或者你可以嘗試像這樣'if(array!= nil || [array count]!= 0)' – Konstantin

1

我覺得你有你使用ARC釋放你的數組中此方法

-(void)viewWillDisappear:(BOOL)animated 
{ 
    // Write Code here to release 
}