In my view I have a button, which is hooked to this method:
-(IBAction)showStore:(id)sender
{
storeSinglePlayer *ssp = [[storeSinglePlayer alloc] init];
ssp.imageH = self.imageURLH;
ssp.imageV = self.imageURLV;
CATransition* transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:ssp animated:NO];
}
When I click this button, it shows me the ‘store single player’ view controller. Also the ‘store single player’ view controller has a back button which is hooked to the following method:
-(IBAction)didPressBack:(id)sender
{
CATransition* transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromBottom;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController popViewControllerAnimated:NO];
}
Clicking the back button also does get me back to my previous view.
But now here is the weird problem. If I repeat this 10 times, i.e. Click the button to show ‘storeSinglePlayer’ and then click the back button on ‘storeSinglePlayer’, I get the error:
[storeSinglePlayer respondsToSelector:]: message sent to deallocated instance 0xe5f6160
And, this not just only on my multiple tries, it just randomly crashes. It would work some time and some times it won’t.
I have ARC enabled.
Can’t get what’s wrong with just this simple code. Read a lot of questions on stack overflow, but none solve my problem.
EDIT: Stack Trace
2012-08-11 11:55:56.353 Magic Buzz[2088:707] (
0 Magic Buzz 0x000c7e19 -[gameOverScreen showStore:] + 700
1 CoreFoundation 0x3769c3fd -[NSObject performSelector:withObject:withObject:] + 52
2 UIKit 0x30891e07 -[UIApplication sendAction:to:from:forEvent:] + 62
3 UIKit 0x30891dc3 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 30
4 UIKit 0x30891da1 -[UIControl sendAction:to:forEvent:] + 44
5 UIKit 0x30891b11 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 492
6 UIKit 0x30892449 -[UIControl touchesEnded:withEvent:] + 476
7 UIKit 0x3089092b -[UIWindow _sendTouchesForEvent:] + 318
8 UIKit 0x30890319 -[UIWindow sendEvent:] + 380
9 UIKit 0x30876695 -[UIApplication sendEvent:] + 356
10 UIKit 0x30875f3b _UIApplicationHandleEvent + 5826
11 GraphicsServices 0x3789222b PurpleEventCallback + 882
12 CoreFoundation 0x37716523 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 38
13 CoreFoundation 0x377164c5 __CFRunLoopDoSource1 + 140
14 CoreFoundation 0x37715313 __CFRunLoopRun + 1370
15 CoreFoundation 0x376984a5 CFRunLoopRunSpecific + 300
16 CoreFoundation 0x3769836d CFRunLoopRunInMode + 104
17 GraphicsServices 0x37891439 GSEventRunModal + 136
18 UIKit 0x308a4cd5 UIApplicationMain + 1080
19 Magic Buzz 0x000b094d main + 96
20 Magic Buzz 0x000b08e8 start + 40
)
2012-08-11 11:55:56.554 Magic Buzz[2088:707] *** -[storeSinglePlayer respondsToSelector:]: message sent to deallocated instance 0xf6cde30
some asynchronous method is calling storeSinglePlayer object after it deallocated, Try removing all the delegates to nil in ViewDidUnload/ViewWillDisappear. If you sending the some query to server and without waiting for it you press the Back button then also it will crash as after completing the request it will call storeSinglePlayer object. Hope this helps