我在使用ARC的Ios 5应用程序中出现以下错误:
*** -[ViewDettaglio respondsToSelector:]: message sent to deallocated instance 0x12193300
在console i上写命令:
info malloc-history 0x12193300
我得到以下堆栈跟踪:
Alloc: Block address: 0x12193300 length: 192 Stack - pthread: 0xa08a3540 number of frames: 31 0: 0x96bdab03 in malloc_zone_calloc 1: 0x96bdaa5a in calloc 2: 0x16f8c93 in class_createInstance 3: 0x170388b in _objc_rootAllocWithZone 4: 0x21af661 in +[NSObject allocWithZone:] 5: 0x17038b9 in _objc_rootAlloc 6: 0x2c4c8 in -[ViewElenco CaricaViewDettaglio:] at /Users/.../ViewElenco.m:186 7: 0x2e550 in -[ViewElenco mapView:annotationView:calloutAccessoryControlTapped:] at /Users/.../ViewElenco.m:337 8: 0x3fa99c 9: 0x405faa in MKLongHash 10: 0x21aeec9 in -[NSObject performSelector:withObject:withObject:] 11: 0x60d5c2 in -[UIApplication sendAction:to:from:forEvent:] 12: 0x60d55a in -[UIApplication sendAction:toTarget:fromSender:forEvent:] 13: 0x6b2b76 in -[UIControl sendAction:to:forEvent:] 14: 0x6b303f in -[UIControl(Internal) _sendActionsForEvents:withEvent:] 15: 0x6b22fe in -[UIControl touchesEnded:withEvent:] 16: 0x632a30 in -[UIWindow _sendTouchesForEvent:] 17: 0x632c56 in -[UIWindow sendEvent:] 18: 0x619384 in -[UIApplication sendEvent:] 19: 0x60caa9 in _UIApplicationHandleEvent 20: 0x1a95fa9 in PurpleEventCallback 21: 0x21811c5 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ 22: 0x20e6022 in __CFRunLoopDoSource1 23: 0x20e490a in __CFRunLoopRun 24: 0x20e3db4 in CFRunLoopRunSpecific 25: 0x20e3ccb in CFRunLoopRunInMode 26: 0x1a94879 in GSEventRunModal 27: 0x1a9493e in GSEventRun 28: 0x60aa9b in UIApplicationMain 29: 0x20bb in main at /Users/.../main.m:14 30: 0x2065 in start
ViewElenco.m第186行的代码如下:
ViewDettaglio *viewq=[[ViewDettaglio alloc] initWithNibName:@"ViewDettaglio" bundle:nil];
这怎么可能发生? 我正在使用UINavigationController从ViewElenco和ViewDettaglio导航。
修改
是否可以在以下代码中使用:
ViewDettaglio* viewDettaglio=[[ViewDettaglio alloc] initWithNibName:@"ViewDettaglio" bundle:nil]; viewDettaglio.idObject=idObj; [self.navigationController pushViewController:viewDettaglio animated:YES];
alloc返回一个解除分配的对象?
答案 0 :(得分:20)
问题已经解决:在ViewDettaglio和ViewElenco中有一个MKMapView,并且委托被设置为容器ViewController。 在UINavigationController中推送新的ViewController时,MapView创建的某个线程可能仍在运行并调用map delegate,即使它不可见。
解决方案是在视图消失时将委托设置为null,并在显示视图之前再次设置它:
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.mapView.delegate=nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.mapView.delegate=self;
}