2

我有一些非常简单的代码,我在其中使用 UINavigationController 并添加了 rootViewController。发生一些处理后,我想弹出当前视图控制器并将其替换为另一个。这似乎工作正常,但我原来的视图控制器没有解除分配。我在它的 dealloc 中设置了一个断点,它永远不会被击中。下面是我的代码。不知道为什么会发生。只是为了测试我是否两次发布 startController 它确实消失了。

StartViewController *startController = [[StartViewController alloc] initWithNibName:@"StartViewController" bundle:[NSBundle mainBundle]]; 

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:startController];
    [nav pushViewController:startController animated:NO];

    self.navController = nav;

    [startController release];
    [nav release];

感谢任何帮助。

4

3 回答 3

1

Your ultimate goal is to bring the view controller's retain count to zero. So make sure that everything the view retains is released and anywhere the view is retained also release.

Please check the following possible causes:

  1. Make sure you pop the view controller from the navController if you have a custom back button. The default Back button will work fine.

  2. Make sure that all your IBOutlets are set to nil in viewDidUnload

    - (void)viewDidUnload 
    {
       [super viewDidUnload];
       self.webView = nil;
    }
    
  3. If your view is an observer to a model class to receive events

For example

model.addObserver(myView);

and sure to also do

model.removeObserver(myView);

I hope this helps.

于 2011-03-17T20:21:08.257 回答
0

看起来你的 self.navController 有一个对它的持有引用。也许放

self.navController =nil; 

适当的地方,以便当视图被弹出时它被释放。

于 2011-03-17T22:00:57.297 回答
0

我试图弹出根视图控制器。我改为使用setViewControllers来自UINavigationController对象的消息来替换我所有的视图控制器。

于 2011-03-18T16:01:04.060 回答