已在alloc命令上将IOS 5消息发送到已解除分配的实例



我在使用ARC的Ios 5应用程序上出现以下错误:

***-[ViewDettaglio responsedsToSelector:]:消息发送到已解除分配的实例0x12193300

在控制台上我写命令:

信息malloc历史0x12193300

我得到以下堆栈跟踪:

Alloc:块地址:0x12193300长度:192堆栈-pthread:0xa08a3540帧数:31malloc_zone_calloc中的0:0x96bdab03胼胝体中的1:0x96bdaa5a类_创建实例中的2:0x16f8c93_objc_rootAllocWithZone中的3:0x170388b4:0x21af661在+[NSObject allocWithZone:]中5:0x17038b9英寸_obj_rootAlloc6:0x2c4c8 in-[ViewElenco CaricaViewDettaglio:]at/Users//观众Elenco.m:1867:0x2e550 in-[ViewElenco mapView:annotationView:calloutAccessoryControlTapped:]at/Users//ViewElenco.m:3378:0x3fa99cMKLongHash中的9:0x405faa10:0x21aeec9 in-[NSObject performSelect:withObject:withObject:]11:0x60d5c2 in-[UIApplication sendAction:to:from:forEvent:]12:0x60d55a在-[UIApplication sendAction:toTarget:fromSender:forEvent:]中13:0x6b2b76 in-[UIControl sendAction:to:forEvent:]14:0x6b303f in-[UIControl(Internal)_sendActionsForEvents:withEvent:]15:0x6b22fe in-[UIControl触摸结束:带事件:]16:0x632a30 in-[UIWindow_sendTouchesForEvent:]17:0x632c56 in-[UIWindow sendEvent:]18:0x619384 in-[UIApplication sendEvent:]_UIApplicationHandleEvent中的19:0x60caa9PurpleEventCallback中的20:0x1a95fa9__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION中的21:0x21811c5____CFRunLoopDoSource1中的22:0x20e602223:__CFRunLoopRun中的0x20e490aCFRunLoopRunSpecific中的24:0x20e3db425:0x20e3ccb处于CFRunLoopRunInMode26:0x1a94879在GSEventRunModal中27:0x1a9493e在GSEventRun中28:0x60aa9b在UIApplicationMain中29:0x20bb,位于/Users//main.m:1430:0x2065启动

ViewElenco.m第186行的代码如下:

ViewDettaglio*viewq=[[ViewDettagrio alloc]initWithNibName:@"ViewDettagio"bundle:nil];

这怎么会发生?我使用UINavigationController从ViewElenco和ViewDettaglio进行导航。

编辑

是否可能在以下代码中:

ViewDettaglio*ViewDettaglio=[[ViewDettagrio alloc]initWithNibName:@"ViewDettagio"bundle:nil];viewDettaglio.idObject=idObj;[self.navigationController pushViewController:viewDettaglio animated:YES];

alloc返回一个已释放的对象?

问题已经解决:在ViewDettaglio和ViewElenco中有一个MKMapView,并且委托被设置为容器ViewController。在UINavigationController中推送新的ViewController时,可能MapView创建的某个线程仍在运行并调用映射委托,即使它不可见。

解决方案是,当视图将取消映射时,将委托设置为null,并在视图出现之前再次设置:

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.mapView.delegate=nil;
}
- (void)viewWillAppear:(BOOL)animated
{    
    [super viewWillAppear:animated];
    self.mapView.delegate=self;
}

最新更新