2012-02-10 7 views
0

更新:私のデバッグで間違いを起こしました。この質問はrelaventではありません - 下記のコメントを参照してください。解約時にUIViewControllerがdeallocまたはviewDidUnloadを受け取らない

注:私は私のアプリが起動すると

を数える自動リファレンスを使用しています - 私はpresentViewController:animated:completionUINavigationController内のビューコントローラを提示。そのビューコントローラは、ナビゲーションスタックに第2のビューコントローラをロードする。 2番目のビューコントローラは、[self.presentingViewController dismissViewControllerAnimated:YES completion:nil]を使用して自身を閉じます。私の問題は、deallocもviewDidUnloadも最初のView Controllerで呼び出されていないことです。しかし、計測器では​​、表示されたView Controllerが一旦消されると、View Controllerが割り当てられなくなったことがわかります。最初のビューコントローラを提示したコードは、私の周りの付着されなければならないsettingsVCへの参照を持っていないが、私のdeallocが呼び出されていない理由を私は知らない、だから、

- (void)viewDidAppear:(BOOL)animated                                                   
{                                                            
    [super viewDidAppear:animated];                                                   

    // check if our context has any accounts                                                 
    if([self.accounts count] == 0)                                              
    {                                                           
     // Display the Add Account View Controller                                               
     MySettingsViewController *settingsVC = [[MySettingsViewController alloc] initWithNibName:@"MySettingsViewController" bundle:nil];                         
     settingsVC.appContext = self.appContext;                                                

     UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:settingsVC];                                
     navVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;                                          

     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)                                      
     {                                                          
      // Display the Add Account View Controller                                              
     }                                                          
     else                                                         
     {                                                          
      navVC.modalPresentationStyle = UIModalPresentationFormSheet;                                          
     }                                                          

     [self presentViewController:navVC animated:YES completion:nil];                                          
    }                                                           
}    

です。どんな助けも素晴らしいだろう。

+0

私はばかです。私が間違ったビューコントローラにテストしていたdeallocメソッドを置いた。だから私のdeallocが意味を成していると呼ばれている。 – Brian

答えて

0

ビューコントローラを正しくリリースしていないため、呼び出されません。

settingsVCnavVCの両方にallocを割り当てて、後でリリースしなければならない両方の参照を所有してください。

あなたはこのようにそれを行うことができます。

- (void)viewDidAppear:(BOOL)animated                                                   
{                                                            
    [super viewDidAppear:animated];                                                   

    // check if our context has any accounts                                                 
    if([self.accounts count] == 0)                                              
    {                                                           
     // Display the Add Account View Controller                                               
     MySettingsViewController *settingsVC = [[MySettingsViewController alloc] initWithNibName:@"MySettingsViewController" bundle:nil];                         
     settingsVC.appContext = self.appContext;                                                

     UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:settingsVC]; 
     navVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;                                          

     // At this points, "settingsVC" is additionally retained by the navigation controller, 
     // so we can release it now. 
     [settingsVC release]; 

     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)                                      
     {                                                          
      // Display the Add Account View Controller                                              
     }                                                          
     else                                                         
     {                                                          
      navVC.modalPresentationStyle = UIModalPresentationFormSheet;                                          
     }                                                          

     [self presentViewController:navVC animated:YES completion:nil]; 

     // At this point "navVC" is retained by UIKit, so we can release it as well. 
     [navVC release]; 
    }                                                           
}   

代替はautorelease両方すぐに行ったことがあるでしょう。

+0

私はAutomatic Reference Countingを使用しています - これは今の場合ですか?申し訳ありません - 私は私の質問にそれを含めたと思った。私はそれを反映するように更新しました。 – Brian

+0

もちろん、ARCはここで違いを生みます...その場合、何が起こっているのか分かりません。申し訳ありません。 – DarkDust

+0

deallocまたはviewDidUnloadのどちらかを呼び出すべきであると私に伝えられますか?意味はメモリ管理とUIViewControllersについての私の理解です。 – Brian

関連する問題