ios - EXC_BAD_ACCESS with ARC. -
i not how debug error. know happening somewhere in uiscrollview when add new data array using function arraybyaddingobjectsfromarray
, try populate data scrollview.
so goes this:
when scroll bottom of page calls function:
-(void)scrollviewdidscroll: (uiscrollview*)scrollview { float scrollviewheight = scrollview.frame.size.height; float scrollcontentsizeheight = scrollview.contentsize.height; float scrolloffset = scrollview.contentoffset.y; if (scrolloffset == 0) { // @ top } else if (scrolloffset + scrollviewheight == scrollcontentsizeheight) { [_scrollviewoutlet scrollrecttovisible:cgrectinset([scrollview bounds], 10, 10) animated:no]; // @ end startingpoint += 36; nslog(@"reached bottom of feed"); if([lastpressedbutton isequaltostring:@"top"]){ [self todaystoppressed:self]; } if([lastpressedbutton isequaltostring:@"latest"]){ [self latestpressed:self]; } } }
startingpoint
integer used in latest pressed function.
- (ibaction)todaystoppressed:(id)sender { nsstring *startpointstring = [@(startingpoint) stringvalue]; _loadingimage.hidden = no; [photo getlatestphotosfromgallery:@"yes" islatest:@"no" atstartingpoint:startpointstring andamountofphotos:@"36" ispoints:@"yes"]; }
getlatestphotosfromgallery in model accesses server , gets json
feed of latest photos , stores userdefaults sends nsnotificationcenter
notification viewcontroller
.
[[nsnotificationcenter defaultcenter] postnotificationname:@"feednotification" object:self];
it runs nsnotificationcenter
, populates images:
this crashes:
- (void) populateimages { dispatch_queue_t myqueue = dispatch_queue_create("my queue",null); dispatch_async(myqueue, ^{ cgfloat contentsizewidth = 0.0; cgsize newsize = _scrollviewoutlet.frame.size; nsarray *images_array = [properties objectforkey:@"feedarray"]; cgrect newframe = _firstimage.frame; for(int = startingpoint; < [images_array count]; i++){ nsdata *archiveddata = [nskeyedarchiver archiveddatawithrootobject:_firstimage]; uibutton *button = [nskeyedunarchiver unarchiveobjectwithdata: archiveddata]; [button addtarget:self action:@selector(imagepressed:) forcontrolevents:uicontroleventtouchupinside]; button.tag = i+1; nslog(@"i mod 3: %i", % 3); int xposi = 0; if(i % 2 == 0){ xposi = 0; } else { xposi = 1; newframe.origin.y += 20+button.frame.size.width; } newframe.origin.x = (20+button.frame.size.width) * xposi; //contentsizewidth = (20+button.frame.size.width) * xposi; contentsizewidth = (button.frame.size.width); [button setframe:newframe]; if(i < [images_array count]){ nsdictionary *images_d = [images_array objectatindex:i]; nsstring *images_d_image_string = [images_d objectforkey:@"pthumb"]; nsnumber *images_id = [images_d objectforkey:@"pid"]; nsstring *images_id_string = images_id; nslog(@"image_id: %@", images_id_string); nsstring *documentsdirectory = [utils getdocumentsdirectorypath]; uiimage *image = [utils loadimage:images_id_string oftype:@"jpg" indirectory:documentsdirectory]; nsstring *jpgfile = [[utils getdocumentsdirectorypath] stringbyappendingstring:images_id_string]; jpgfile = [jpgfile stringbyappendingstring:@".jpg"]; nslog(@"jpgfile: %@", jpgfile); bool fileexists = no; if([[nsfilemanager defaultmanager] fileexistsatpath:jpgfile]){ fileexists = yes; nslog(@"image named %@ exists", images_id_string); } else { fileexists = no; // } if([[nsfilemanager defaultmanager] fileexistsatpath:jpgfile]){ dispatch_async(dispatch_get_main_queue(), ^{ [[button imageview] setimage:image]; [button setimage:image forstate:uicontrolstatenormal]; [button setimage:image forstate:uicontrolstateselected]; [[button imageview] setcontentmode: uiviewcontentmodescaleaspectfit]; }); } else { uiimage *imagetoset = [utils getimagefromurl:images_d_image_string]; dispatch_async(dispatch_get_main_queue(), ^{ [button setimage:imagetoset forstate:uicontrolstatenormal]; [button setimage:imagetoset forstate:uicontrolstateselected]; [[button imageview] setcontentmode: uiviewcontentmodescaleaspectfit]; [[button imageview] setimage:imagetoset]; }); [utils saveimage:imagetoset withfilename:images_id_string oftype:@"jpg" indirectory:[utils getdocumentsdirectorypath]]; } dispatch_async(dispatch_get_main_queue(), ^{ [button setalpha:1.0f]; }); } else { dispatch_async(dispatch_get_main_queue(), ^{ [button setalpha:0.2f]; button.userinteractionenabled = no; [button.imageview setcontentmode:uiviewcontentmodescaleaspectfit]; //[button sizetofit]; }); } dispatch_async(dispatch_get_main_queue(), ^{ [_scrollviewoutlet addsubview:button]; }); if(i % 4 == 0){ newsize.height+=20+button.frame.size.width; } } newsize.width = contentsizewidth; dispatch_async(dispatch_get_main_queue(), ^{ [_scrollviewoutlet setcontentsize:newsize]; _loadingimage.hidden = yes; }); }); }
Comments
Post a Comment