iphone - Can't understand why my tableview with GCD is crashing -
i've finished re-writing this, , covered every conceivable angle can think of. don't know why crashing. perhaps me figure out.
this cellforrowatindexpath code:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; jhomeviewcell *cell = (jhomeviewcell *)[tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[jhomeviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; cell.delegate = self; } cell.cellcontent.cellinfo = [self cellinfoforcellatindexpath:indexpath]; if (cell.cellcontent.cellinfo.thumbnailscomplete == yes || cell.cellcontent.cellinfo.thumbnailsbeingcreated == yes) { [cell.cellcontent setneedsdisplay]; } else { [cell.cellcontent setup]; } return cell; } and in cellcontent, there's setup method:
-(void)setup { [self setneedsdisplay]; self.cellinfo.thumbnailsbeingcreated = yes; nsmanagedobjectid *entryid = self.cellinfo.objectid; dispatch_queue_t cellsetupqueue = dispatch_queue_create("com.journalized.setupcell", null); dispatch_async(cellsetupqueue, ^{ nsmanagedobjectcontext *newmoc = [[nsmanagedobjectcontext alloc] init]; nspersistentstorecoordinator *coordinator = [[coredatastore mainstore] context].persistentstorecoordinator; [newmoc setpersistentstorecoordinator:coordinator]; nsnotificationcenter *notify = [nsnotificationcenter defaultcenter]; [notify addobserver:self selector:@selector(mergechanges:) name:nsmanagedobjectcontextdidsavenotification object:newmoc]; entry *entry = (entry *)[newmoc objectwithid:entryid]; [newmoc save:nil]; int = 0; while (i < self.cellinfo.numberofthumbnailstodraw) { nslog(@"number of thumbnails: %i %i %i", self.cellinfo.numberofthumbnailstodraw, entry.media.count, i); media *media = [entry.media objectatindex:i]; uiimage *image = [media getthumbnail]; bool success = [newmoc save:nil]; //nslog(@"time: %@ success: %i", entry.entrytableinfo.creationtimestring, success); [self.cellinfo.thumbnails setobject:image forkey:[nsnumber numberwithint:i]]; i++; } [[nsnotificationcenter defaultcenter] removeobserver:self]; dispatch_async(dispatch_get_main_queue(), ^{ self.cellinfo.thumbnailscomplete = yes; [self setneedsdisplay]; }); }); dispatch_release(cellsetupqueue); it crashes on line:
media *media = [entry.media objectatindex:i]; with error:
index 1 beyond bounds [0 .. 0] the nslog above that...
nslog(@"number of thumbnails: %i %i %i", self.cellinfo.numberofthumbnailstodraw, entry.media.count, i); gives result:
number of thumbnails: 2 1 1 which sort of explains crash, except value set in [cellinfoforcellatindexpath:]; method, so:
cellinfo.numberofmediaitems = entry.media.count; cellinfo.numberofthumbnailstodraw = min(cellinfo.numberofmediaitems, 3); i don't know problem occurring, or why it's occurring, can't move on app until part fixed.
well numberofthumbnailstodraw 2 meaning while loop 0, 1, count of entry.media 1 has 0 index of course it'll crash.
Comments
Post a Comment