I have a class that handle delegate methods for a table. I have used IB and dragged into the NIB a UITableViewDelegate that I changed to my class. I have also included a UITableView object in the NIB where I connect delegate and dataSource to my TableViewDelegate class.
My class gets its table data from the internet so I get my delegated methods called once at view design and return a count of 0 because my data has not yet arrived. When I finish getting all the data I do a [myTable reloadData] and my delegate methods get call again. The problem is that I get the numberOfRowsInSection called, where I now return the number of lines but never get the cellForRowAtIndexPath called and instead get an EXC_BAD_ACCESS. After enabling stack history and Zombies I found out that the dealloc for the class is being called.
dealloc restTable Class - produced with an NSLOG inside the dealloc method.
2011-02-27 00:33:59.979 PesquisaMapa[3526:207] * -[restTable tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x5624190 As my obj开发者_StackOverflowect was initially created in IB and my IBOutlet to it is declared in the main class header file and only deallocated when the application finishes, I really dont understand why this instance of the class is being deallocated. My stack is as follows:
(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 in +[NSObject(NSObject) allocWithZone:] 5: 0xedadfa in +[NSObject(NSObject) alloc] 6: 0x4c1205 in -[UIClassSwapper initWithCoder:] 7: 0x5a79e4 in UINibDecoderDecodeObjectForValue 8: 0x5a8693 in -[UINibDecoder decodeObjectForKey:] 9: 0x4c0f43 in -[UIRuntimeConnection initWithCoder:] 10: 0x5a79e4 in UINibDecoderDecodeObjectForValue 11: 0x5a72dc in UINibDecoderDecodeObjectForValue 12: 0x5a8693 in -[UINibDecoder decodeObjectForKey:] 13: 0x4c0200 in -[UINib instantiateWithOwner:options:] 14: 0x4c2081 in -[NSBundle(UINSBundleAdditions) 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: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 CFRUNLOOP_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 in start
It looks like some cleanup is going on in didFinishLaunchingWithOptions of my main class.
Any ideias on what I'm doing wrong?
thanks, PC
UITableView (and most other classes) don't retain their delegates. That means that if you don't retain the delegate in some manner (e.g. by assigning it to a property declared retain) then it will be disposed of at some point by the main run loop.
精彩评论