ios - iCarousel performance issue on iPad -


i'm using nick lockwood's icarousel ipad app. right it's carousel of 15 full screen images.

i setup single view project, add icarousel view in storyboard, add it's view controller data source , put code datasource methods:

- (nsuinteger)numberofitemsincarousel:(icarousel *)carousel {     return 15; }  - (uiview *)carousel:(icarousel *)carousel viewforitematindex:(nsuinteger)index reusingview:(uiview *)view {     uiimage* img = [uiimage imagenamed:[nsstring stringwithformat:@"image%d.jpg", index]];     uiimageview* imgview = [[uiimageview alloc] initwithimage:img];      return imgview; } 

this works, first time scroll through items can notice little performance hit when new item being added carousel. not happen second time go through items.

you can see mean in profiler screenshot. peaks in first half first time scroll through images, again , there no peaks , no performance hit.

how can fix this?

enter image description here

edit

i isolated 1 of peaks on instruments , call tree

enter image description here

edit

the code jcesar suggestion

- (void)viewdidload {     [super viewdidload];      nsmutablearray* urls_aux = [[nsmutablearray alloc] init];     (int = 0; i<15; i++) {         nsstring *urlpath = [[nsbundle mainbundle] pathforresource:[nsstring stringwithformat:@"captura%d", i] oftype:@"jpg"];         nsurl *url = [nsurl fileurlwithpath:urlpath];          [urls_aux addobject:url];     }     self.urls = urls_aux.copy;      self.carousel.datasource = self;     self.carousel.type = icarouseltypelinear; }  - (uiview *)carousel:(icarousel *)carousel viewforitematindex:(nsuinteger)index reusingview:(uiview *)view {      if (view == nil) {         view = [[[asyncimageview alloc] initwithframe:cgrectmake(0, 0, 1024, 768)] autorelease];         view.contentmode = uiviewcontentmodescaleaspectfit;     }      [[asyncimageloader sharedloader] cancelloadingimagesfortarget:view];     ((asyncimageview *)view).imageurl = [self.urls objectatindex:index];      return view; } 

i don't think orthodox solution, works.

what use icarousel's method insertitematindex:animated: add images 1 @ time on setup. performance gets hit then, after runs smoothly.

- (void)viewdidload {     [super viewdidload];      self.images = [[nsmutablearray alloc] init];     self.carousel.datasource = self;     self.carousel.type = icarouseltypelinear;      (int = 0; i<15; i++) {         uiimage* img = [uiimage imagenamed:[nsstring stringwithformat:@"captura%d.jpg", i]];         [self.images addobject:img];         [self.carousel insertitematindex:i animated:no];     } }  - (nsuinteger)numberofitemsincarousel:(icarousel *)carousel {     return self.images.count; }  - (uiview *)carousel:(icarousel *)carousel viewforitematindex:(nsuinteger)index reusingview:(uiview *)view {     uiimage* img = [self.images objectatindex:index];     uiimageview* imgview = [[uiimageview alloc] initwithimage:img];      return imgview; } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -