Pregunta

My project using ARC, so I can't use retain nor release, in ViewController A, I init ViewController B and add its view as a subview:

ViewControllerB *viewB = [[ViewControllerB alloc] init];

[self.view addSubview:viewB.view];

And in ViewControllerB, I make a button and when user click on it, the view will removed from superview:

[self.view removeFromSuperview];

And the result is EXC_BAD_ACCESS. Please help me and sorry about my English.

¿Fue útil?

Solución

I think viewB is not local variable.

Otros consejos

I have the same problem too..

Try something like this:

NSLog("self.view retain count: %d", self.view.retainCount);
[self.view removeFromSuperview];
NSLog("self.view retain count: %d", self.view.retainCount);

or:

NSLog("self.view.superview retain count: %d", self.view.superview.retainCount);
[self.view removeFromSuperview];
NSLog("self.view.superview retain count: %d", self.view.superview.retainCount);

It's not good practice, but maybe you will catch a memory leak error... If you are using ARC - it doesn't protect you from memory management errors...

I'm sorry for my English if something wrong.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top