문제

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.

도움이 되었습니까?

해결책

I think viewB is not local variable.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top