Search code examples
uiviewcontrollerexc-bad-accessaddsubviewsuperview

EXC_BAD_ACCESS when remove from superview


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.


Solution

  • I think viewB is not local variable.