ios - Adding images to UIScrollview with horizontal infinity style scrolling -


so i'm doing first uiscrollview placing resized images it, when end of first set of results , go add 2nd set etc., view resets start. i'm not sure if it's adding images, x value being counted forward correctly, uiscrollview should resizing, can assume placing next set of images on top of old images.

what doing wrong here?

-(void)addscrollviewimages {     // setup our uiscrollview     self.scrollview.delegate = self;     self.scrollview.pagingenabled = yes;     self.scrollview.showshorizontalscrollindicator = no;     self.scrollview.showsverticalscrollindicator = no;     self.scrollview.contentsize = cgsizemake(self.scrollview.frame.size.width,self.scrollview.frame.size.height);      // hit our server data     nsstring *encodedkeywords =[self.keyword stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];     self.results = [self fetchimageresults:encodedkeywords];      // loop on image results     (id image in self.results)     {         uiimageview *imageview = [[uiimageview alloc] initwithframe: cgrectmake(self.x, 0, self.screenwidth, self.screenhight)];          nsstring *imageurl = image[@"url"];         nsdata *image = [nsdata datawithcontentsofurl:[nsurl urlwithstring:imageurl]];          // resize image device         [imageview setimage:[self imagescalecroptosize:[uiimage imagewithdata:image]]];          [self.scrollview addsubview: imageview];         self.x = (self.x + imageview.frame.size.width);          // resize frame width         if(self.x > self.view.frame.size.width) self.scrollview.contentsize = cgsizemake(self.x, self.scrollview.frame.size.height);     } } // gets json data , processes little -(nsarray*)fetchimageresults:(nsstring*)keyword {     //this should quick     nserror *error = nil;     nsurl *apiurl = [nsurl urlwithstring:[nsstring stringwithformat:@"http://example.com/api/v1/search?q=%@", keyword]];     nsdata *jsondata = [nsdata datawithcontentsofurl:apiurl];     nsdictionary *result = [nsjsonserialization jsonobjectwithdata:jsondata options:0 error:&error];     return result[@"results"]; } // scroll index management - (void)scrollviewdidscroll:(uiscrollview *)sender {     float indexnum = self.scrollview.contentoffset.x / self.scrollview.frame.size.width;     if(floor(indexnum) == indexnum) {         int num = (int)indexnum;          nslog(@"viewing %@",self.results[num]);          // if @ end, load more         if(num == (self.results.count-1) ) {             dispatch_async(dispatch_get_main_queue(), ^{                 [self addscrollviewimages];             });         }     } } 

you killing not using uitableview. make uitableview prototype uitableviewcells. subclass cell, imageviewtablecell, , make property uiimageview fills size.

the rest using uitableviewdelegate , uitableviewdatasource.

tutorial setting tableview


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -