views:

154

answers:

2

I have one UINavigationController that I use like this:

DetailsViewController *controller = [DetailsViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
[controller release];

Of course this code works well.

The problem: when I send the popViewControllerAnimated: to the UINavigationController, the DetailsViewController it is removed from the stack, but it is not released if there is no animation occurring. (That is, dealloc is not called, and the DetailsViewController remains with a retainCount of 1).

Does anyone have any idea of what's happening here? Is the animated parameter being used improperly?

A: 

If the main problem are the observed notifications, why not remove the observers in the "-(void)viewWillDisappear:(BOOL)animated" - method?

Dshutsi
Because I still want the notification to be received if the controller is hidden (for example the user selects another tab). I think that viewWillDisappear: is called every time the controller is not shown in the display, isn't it?
Eugenio Depalo
You could try viewDidUnload method which should be called when the view is released from it's controller.Have a look at the documentation on: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW36
Dshutsi
A: 

what Dshutsi suggests is right. If you want the notifications to be removed, that is better called in the viewDidUnload method of the controller. This method is called when the controller is unloaded from the stack. I am just quoting this because we cannot vote up the comment as an answer.

Nareshkumar
In the documentation it is written that viewDidUnload is called only in low-memory conditions. I guess this is not the case. While this is not really the answer I was looking for (the controller *should* be released), I will accept it since it is the only working solution besides passing YES to the animated parameter! Thank you.
Eugenio Depalo