2 a4311462 a4311462 于 2015.06.25 16:51 提问

ARC下,使用uitableview的时候刚显示就调用了dealloc
ios

调试跟进的时候发现,进入了viewDidLoad,viewWillAppear,然后处理了一些显示细节,页面结果是正确的,紧接着就调用了dealloc,结果导致我对tableview的任何操作都返回,message sent to deallocated instance,用僵尸模式调试跟进,发现....看不懂,就过来问了

_NSZombie_CityListViewContoller
stack[0]: addr = 0x15f381a0, type=malloc, frames:
     [0] 0x0000000035278469 libsystem_malloc.dylib`malloc_zone_calloc + 129
     [1] 0x00000000352783d7 libsystem_malloc.dylib`calloc + 51
     [2] 0x0000000034bc3419 libobjc.A.dylib`class_createInstance + 41
     [3] 0x0000000034bd4eb5 libobjc.A.dylib`_objc_rootAlloc + 33
     [4] 0x000000002a184815 UIKit`-[UIClassSwapper initWithCoder:] + 117
     [5] 0x000000002a23e915 UIKit`UINibDecoderDecodeObjectForValue + 853
     [6] 0x000000002a23e5b3 UIKit`-[UINibDecoder decodeObjectForKey:] + 335
     [7] 0x000000002a184497 UIKit`-[UIRuntimeConnection initWithCoder:] + 151
     [8] 0x000000002a23e915 UIKit`UINibDecoderDecodeObjectForValue + 853
     [9] 0x000000002a23e86b UIKit`UINibDecoderDecodeObjectForValue + 683
     [10] 0x000000002a23e5b3 UIKit`-[UINibDecoder decodeObjectForKey:] + 335
     [11] 0x000000002a183b7f UIKit`-[UINib instantiateWithOwner:options:] + 959
     [12] 0x000000002a2ff81d UIKit`-[UIStoryboard instantiateViewControllerWithIdentifier:] + 197
     [13] 0x00000000000e62f3 MapTest`-[OfflineMapViewController actionButtonChickCityList:] + 155 at ViewController.m:1207:28
     [14] 0x0000000029de447b UIKit`-[UIApplication sendAction:to:from:forEvent:] + 71
     [15] 0x0000000029de4421 UIKit`-[UIControl sendAction:to:forEvent:] + 45
     [16] 0x0000000029dcefc5 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 585
     [17] 0x0000000029de3e61 UIKit`-[UIControl touchesEnded:withEvent:] + 585
     [18] 0x0000000029de3b33 UIKit`-[UIWindow _sendTouchesForEvent:] + 523
     [19] 0x0000000029ddd441 UIKit`-[UIWindow sendEvent:] + 541
     [20] 0x0000000029db3605 UIKit`-[UIApplication sendEvent:] + 197
     [21] 0x000000002a029cff UIKit`_UIApplicationHandleEventFromQueueEvent + 14539
     [22] 0x0000000029db2007 UIKit`_UIApplicationHandleEventQueue + 1351
     [23] 0x000000002658022f CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
     [24] 0x000000002657f643 CoreFoundation`__CFRunLoopDoSources0 + 223
     [25] 0x000000002657dcc1 CoreFoundation`__CFRunLoopRun + 769
     [26] 0x00000000264c99a1 CoreFoundation`CFRunLoopRunSpecific + 477
     [27] 0x00000000264c97b3 CoreFoundation`CFRunLoopRunInMode + 107
     [28] 0x000000002dfe71a9 GraphicsServices`GSEventRunModal + 137
     [29] 0x0000000029e13095 UIKit`UIApplicationMain + 1441
     [30] 0x00000000000f22e9 MapTest`main + 109 at main.m:14:16
     [31] 0x0000000035186aaf libdyld.dylib`start + 3
     [32] 0x37b4e9dd

1个回答

zhao18933
zhao18933   2015.06.26 09:23

没有看到代码很难确定原因
不过有一点是确定的,就是你TableView的引用计数为0了才会释放
至于TableView引用计数为何归零,你可以从以下几个方面分析:
1. 引用tableView的属性或者变量已经置为nil,并且tableView已经被removeFromSuperview
2. 如果你的viewController中引用了tableView,并且add到了view上面,那很有可能你的viewController已经被释放了
顺着第二点的思路,你可以看看你的viewController是不是没有被引用,而仅仅是把它的view加到了某个视图上面

a4311462
a4311462 我原以为只添加控制器的视图就能达到retain的目的,所以还真没引用,后来用addChildViewController的方式ratain果然解决了这个问题,非常感谢!!
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片