Pergunta

I have a two ViewControllers A and B, in between I use UINavigationController's pushViewController function to navigate, for example when press button on A, it navigates to B by executing:

[self.navigationController pushViewController:[[BViewController alloc] init] animated:YES];

When press button on B, it navigates to A by the same way.

I think every time I navigate in this way, I am creating a new instance of a view controller without deleting the old one. For example, if I navigate A -> B -> A, there will be two A controllers.

How can I better manage the memory in this case? Is there a recommended pattern to reuse generated view controllers (like singleton view controller?), or how should I properly release the view controller which is not in use?

Thank you

Foi útil?

Solução

Usually, if you navigate between A and B, the workflow should be like:

Push, A -> B,

[self.navigationController pushViewController:[[BViewController alloc] init] animated:YES];

Then Pop, A <- B,

[self.navigationController popViewControllerAnimated:YES];

So that A is the same instance.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top