objective c - Determine when UITableViewCell is deallocated -


i using core data in app along nsfetchedresultscontroller populate table. database has 40k+ entries table rather long. each table cell has thumbnail image loaded web using sdwebimage. works great if scroll slowly, if begin scroll fast within couple of seconds crash.

nszombies isn't showing useful.

i'm guessing has sdwebimage , loading web. way sdwebimage works loading image in background setting downloaded image after completes downloading (wordy). thought cells being deallocated uitableview, sdwebimage tries set image on deallocated cell. if can determine when uitableviewcell going deallocated can stop sdwebimage downloading process , fix issue.

i've tried add

- (void)dealloc {     nslog(@"dealloc"); } 

to catch when cell going deallocated never anything.

edit have -(void)dealloc method in subclass uitableviewcell.

edit here where/how create cell

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath  {  static nsstring* inventorycellid = @"inventorycustomcellid";   inventorycustomcell* cell = (inventorycustomcell *)[tableview dequeuereusablecellwithidentifier:inventorycellid forindexpath:indexpath];   [self configurecell:cell atindexpath:indexpath];   return cell;  }   - (void)configurecell:(inventorycustomcell *)cell atindexpath:(nsindexpath *)indexpath {      [cell formatcellwithproduct:[fetchedresultscontroller objectatindexpath:indexpath] enableadding:no];      cell.openthumbnailbutton.tag = indexpath.row;      [cell.openthumbnailbutton addtarget:self action:@selector(presentthumbnailviewwithcell:) forcontrolevents:uicontroleventtouchupinside]; } 

in custom cell configuration method being called:

- (void)formatcellwithproduct:(product*)product enableadding:(bool)addingenabled {      self.titlelabel.text = product.part_number;     self.partnumberlabel.text = [[[product.manufacturer allobjects] objectatindex:0] name];      //the sdwebimage uiimageview category method     [self.thumbimageview setimagewithurl:[nsurl urlwithstring:product.photo] placeholderimage:[uiimage imagenamed:@"icon.png"]]; } 

edit here sdwebimage method downloads image , sets it.

- (void)setimagewithurl:(nsurl *)url placeholderimage:(uiimage *)placeholder options:(sdwebimageoptions)options progress:(sdwebimagedownloaderprogressblock)progressblock completed:(sdwebimagecompletedblock)completedblock; {     [self cancelcurrentimageload];      self.image = placeholder;      if (url)     {         __weak uiimageview *wself = self;         id<sdwebimageoperation> operation = [sdwebimagemanager.sharedmanager downloadwithurl:url options:options progress:progressblock completed:^(uiimage *image, nserror *error, sdimagecachetype cachetype, bool finished)         {             __strong uiimageview *sself = wself;             if (!sself) return;             if (image)             {                 sself.image = image;                 [sself setneedslayout];             }             if (completedblock && finished)             {                 completedblock(image, error, cachetype);             }         }];         objc_setassociatedobject(self, &operationkey, operation, objc_association_retain_nonatomic);     } } 

table views don't tend allocate , deallocate table view cells much. creating cells expensive, reused when possible, rather being discarded when go off screen.

the uitableviewdelegate method -tableview:didenddisplayingcell:forrowatindexpath: better place update cells cancel downloads or other no-longer-relevant operations.

it each call -setimagewithurl:etc:etc: trying cancel previous downloads image view, though.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -