I have an B UIViewController and there’s close button inside.
-(IBAction) close:(id) sender
From A viewcontroller I present the B viewcontroller like this
[self presentViewController:B animated:YES completion:NULL];
then everything is OK, I can hit the close button inside B.
However if I do
B* bcontrol=[[B alloc] init];
[self.view addsubview bcontrol.view];
then this way, if I hit the close button, it generate EXEC_BAD_ACCESS error.
why is that? any ideas?
You’re using ARC, I assume.
You create bcontrol as a local variable and don’t keep a reference to it, so ARC releases it when you strip out its view. Then your button tries to trigger an action in a deallocated object…and you know the rest.
Make B a strong property so that it stays around while you need it’s view.