在我看来,我有一个按钮,它与这个方法 Hook :
-(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];
}
当我单击此按钮时,它会显示“商店单人游戏” View Controller 。此外,'store single player' View Controller 有一个后退按钮,它连接到以下方法:
-(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];
}
点击后退按钮也能让我回到之前的 View 。
但现在奇怪的问题来了。如果我重复此操作 10 次,即单击按钮以显示“storeSinglePlayer”,然后单击“storeSinglePlayer”上的后退按钮,我会收到错误消息:
[storeSinglePlayer respondsToSelector:]: message sent to deallocated instance 0xe5f6160
而且,这不仅仅是在我多次尝试时,它只是随机崩溃。它有时会起作用,有时却不起作用。
我启用了 ARC。
仅仅通过这个简单的代码就无法找出问题所在。看了很多stack overflow的问题,都没有解决我的问题。
编辑:堆栈跟踪
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
最佳答案
一些异步方法在释放后调用 storeSinglePlayer 对象,尝试在 ViewDidUnload/ViewWillDisappear 中将所有委托(delegate)移除为 nil。如果您将一些查询发送到服务器并且没有等待它您按下后退按钮那么它也会崩溃,因为在完成请求后它将调用 storeSinglePlayer 对象。希望这有帮助
关于iphone - 奇怪的行为 : Message Sent to deallocated instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11912394/