1

我有一个处理表的委托方法的类。我已经使用了 IB 并将一个 UITableViewDelegate 拖到了 NIB 中,该 UITableViewDelegate 已更改为我的班级。我还在 NIB 中包含了一个 UITableView 对象,我在其中将委托和数据源连接到我的 TableViewDelegate 类。

我的类从 Internet 获取其表数据,因此我在视图设计时调用了一次委托方法并返回计数 0,因为我的数据尚未到达。当我完成获取所有数据时,我会执行 [myTable reloadData] 并且我的委托方法会再次被调用。问题是我调用了 numberOfRowsInSection,现在我返回行数,但从未调用 cellForRowAtIndexPath 而是获取 EXC_BAD_ACCESS。在启用堆栈历史和僵尸后,我发现正在调用该类的 dealloc。

dealloc restTable 类 - 在 dealloc 方法中使用 NSLOG 生成。

2011-02-27 00:33:59.979 PesquisaMapa[3526:207] * -[restTable tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x5624190 因为我的对象最初是在 IB 中创建的,而我的 IBOutlet 是在 main 中声明的类头文件并且仅在应用程序完成时才被释放,我真的不明白为什么这个类的实例被释放。我的堆栈如下:

(gdb) info malloc-history 0x5624190 Alloc: Block address: 0x05624190 length: 160 Stack - pthread: 0xa0a5f540 number of frames: 34 0: 0x9876f103 in malloc_zone_calloc 1: 0x9876f05a in calloc 2: 0x110ad0f in _internal_class_createInstanceFromZone 3: 0x110d87d in class_createInstance 4: 0xedaff8在 +[NSObject(NSObject) allocWithZone:] 5: 0xedadfa 在 +[NSObject(NSObject) alloc] 6: 0x4c1205 在 -[UIClassSwapper initWithCoder:] 7: 0x5a79e4 在 UINibDecoderDecodeObjectForValue 8: 0x5a8693 在 -[UINibDecoder decodeObjectForKey:] 9: 0x4c0f43在 -[UIRuntimeConnection initWithCoder:] 10: 0x5a79e4 在 UINibDecoderDecodeObjectForValue 11: 0x5a72dc 在 UINibDecoderDecodeObjectForValue 12: 0x5a8693 在 -[UINibDecoder decodeObjectForKey:] 13: 0x4c0200 在 -[UINib instantiateWithOwner:options:] 14:0x4c2081 in -[NSBundle(UISBundleAdditions) loadNibNamed:owner:options:] 15: 0x37aa94 in -[UIViewController _loadViewFromNibNamed:bundle:] 16: 0x378709 in -[UIViewController loadView] 17: 0x3785e3 in -[UIViewController view] 18: 0x22fe in - [PesquisaMapaAppDelegate application:didFinishLaunchingWithOptions:] at /Users/pcasqueiro/Documents/PesquisaMapa/Classes/PesquisaMapaAppDelegate.m:24 19: 0x2cb1fa in -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] 20: 0x2cd55e in -[UIApplication _runWithURL:payload: :statusBarStyle:statusBarHidden:] 21: 0x2d7db2 in -[UIApplication handleEvent:withNewEvent:] 22: 0x2d0202 in -[UIApplication sendEvent:] 23: 0x2d5732 in _UIApplicationHandleEvent 24: 0x18eca36 in PurpleEventCallback 25: 0xf98064 inoptions:] 15: 0x37aa94 in -[UIViewController _loadViewFromNibNamed:bundle:] 16: 0x378709 in -[UIViewController loadView] 17: 0x3785e3 in -[UIViewController view] 18: 0x22fe in -[PesquisaMapaAppDelegate application:didFinishLaunchingWithOptions:] at /Users/pcasqueiro /Documents/PesquisaMapa/Classes/PesquisaMapaAppDelegate.m:24 19: 0x2cb1fa in -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] 20: 0x2cd55e in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] 21: 0x2d7db2 in -[ UIApplication handleEvent:withNewEvent:] 22: 0x2d0202 in -[UIApplication sendEvent:] 23: 0x2d5732 in _UIApplicationHandleEvent 24: 0x18eca36 in PurpleEventCallback 25: 0xf98064 inoptions:] 15: 0x37aa94 in -[UIViewController _loadViewFromNibNamed:bundle:] 16: 0x378709 in -[UIViewController loadView] 17: 0x3785e3 in -[UIViewController view] 18: 0x22fe in -[PesquisaMapaAppDelegate application:didFinishLaunchingWithOptions:] at /Users/pcasqueiro /Documents/PesquisaMapa/Classes/PesquisaMapaAppDelegate.m:24 19: 0x2cb1fa in -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] 20: 0x2cd55e in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] 21: 0x2d7db2 in -[ UIApplication handleEvent:withNewEvent:] 22: 0x2d0202 in -[UIApplication sendEvent:] 23: 0x2d5732 in _UIApplicationHandleEvent 24: 0x18eca36 in PurpleEventCallback 25: 0xf98064 in0x378709 in -[UIViewController loadView] 17: 0x3785e3 in -[UIViewController view] 18: 0x22fe in -[PesquisaMapaAppDelegate application:didFinishLaunchingWithOptions:] at /Users/pcasqueiro/Documents/PesquisaMapa/Classes/PesquisaMapaAppDelegate.m:24 19: 0x2cb1fa [UIApplication _callInitializationDelegatesForURL:payload:suspended:] 20: 0x2cd55e in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] 21: 0x2d7db2 in -[UIApplication handleEvent:withNewEvent:] 22: 0x2d0202 in -[UIApplication sendEvent:] 23 :_UIApplicationHandleEvent 中的 0x2d5732 24:PurpleEventCallback 中的 0x18eca36 25:0xf980640x378709 in -[UIViewController loadView] 17: 0x3785e3 in -[UIViewController view] 18: 0x22fe in -[PesquisaMapaAppDelegate application:didFinishLaunchingWithOptions:] at /Users/pcasqueiro/Documents/PesquisaMapa/Classes/PesquisaMapaAppDelegate.m:24 19: 0x2cb1fa [UIApplication _callInitializationDelegatesForURL:payload:suspended:] 20: 0x2cd55e in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] 21: 0x2d7db2 in -[UIApplication handleEvent:withNewEvent:] 22: 0x2d0202 in -[UIApplication sendEvent:] 23 :_UIApplicationHandleEvent 中的 0x2d5732 24:PurpleEventCallback 中的 0x18eca36 25:0xf98064] 在 /Users/pcasqueiro/Documents/PesquisaMapa/Classes/PesquisaMapaAppDelegate.m:24 19: 0x2cb1fa 在 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] 20: 0x2cd55e 在 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] 21: 0x2d7db2 in -[UIApplication handleEvent:withNewEvent:] 22: 0x2d0202 in -[UIApplication sendEvent:] 23: 0x2d5732 in _UIApplicationHandleEvent 24: 0x18eca36 in PurpleEventCallback 25: 0xf98064 in] 在 /Users/pcasqueiro/Documents/PesquisaMapa/Classes/PesquisaMapaAppDelegate.m:24 19: 0x2cb1fa 在 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] 20: 0x2cd55e 在 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] 21: 0x2d7db2 in -[UIApplication handleEvent:withNewEvent:] 22: 0x2d0202 in -[UIApplication sendEvent:] 23: 0x2d5732 in _UIApplicationHandleEvent 24: 0x18eca36 in PurpleEventCallback 25: 0xf98064 in_UIApplicationHandleEvent 24 中的 0x2d5732:PurpleEventCallback 中的 0x18eca36 25:0xf98064_UIApplicationHandleEvent 24 中的 0x2d5732:PurpleEventCallback 中的 0x18eca36 25:0xf98064CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION 26: 0xef86f7 in __CFRunLoopDoSource1 27: 0xef5983 in __CFRunLoopRun 28: 0xef5240 in CFRunLoopRunSpecific 29: 0xef5161 in CFRunLoopRunInMode 30: 0x2ccfa8 in -[UIApplication _run] 31: 0x2d942e in UIApplicationMain 32: 0x228c in main at /Users/pcasqueiro/Documents/PesquisaMapa/ main.m:14 33: 0x221d 开始

看起来我的主类的 didFinishLaunchingWithOptions 正在进行一些清理工作。

关于我做错了什么的任何想法?

谢谢,电脑

4

1 回答 1

0

UITableView(和大多数其他类)不保留它们的委托。这意味着如果您不以某种方式保留委托(例如,通过将其分配给声明为保留的属性),那么它将在某个时候被主运行循环处理掉。

于 2011-02-27T01:06:35.240 回答