objective c - Load array of images into slider in IOS -


i have used slider this in project.

in slider using static images pass slider , these images visible in slider. have array of images coming service, passed array slider, slider works fine not show images in slider. i'm confused why not displaying it. code slider is,

 nsuserdefaults *userdefaults = [nsuserdefaults standarduserdefaults]; nsarray *arrayofimages = [userdefaults objectforkey:@"property_images"]; nslog(@"ggg %@",arrayofimages);   //self.imagesdata=[[nsarray alloc]init]; self.imagesdata = arrayofimages;  //[_image1 mutablecopy];  //@[@"image1.jpg", @"image2.jpg", @"image3.jpg"]; nslog(@"image array %@",_imagesdata); for(int i=0; i<self.imagesdata.count;i++){     uiimageview *imageview = [[uiimageview alloc] initwithframe:cgrectmake(cgrectgetwidth(self.view.frame) * i, 0, cgrectgetwidth(self.view.frame), cgrectgetheight(self.scrollview.frame))];     imageview.contentmode = uiviewcontentmodescaleaspectfill;     imageview.image = [uiimage imagenamed:[self.imagesdata objectatindex:i]];     [self.scrollview addsubview:imageview]; } self.scrollview.delegate = self; index=0;   // progammatically init tapagecontrol custom dot view. self.custompagecontrol2 = [[tapagecontrol alloc] initwithframe:cgrectmake(20,self.scrollview.frame.origin.y+self.scrollview.frame.size.height,self.scrollview.frame.size.width,40)];//cgrectmake(0, cgrectgetmaxy(self.scrollview.frame) - 100, cgrectgetwidth(self.scrollview.frame), 40) // example touch bullet event self.custompagecontrol2.delegate      = self; self.custompagecontrol2.numberofpages = self.imagesdata.count; self.custompagecontrol2.dotsize       = cgsizemake(20, 20); self.scrollview.contentsize = cgsizemake(cgrectgetwidth(self.view.frame) * self.imagesdata.count, cgrectgetheight(self.scrollview.frame)); [self.view addsubview:self.custompagecontrol2]; 

and further functions of slider this,

-(void)viewdidappear:(bool)animated{         timer=[nstimer scheduledtimerwithtimeinterval:3 target:self selector:@selector(runimages) userinfo:nil repeats:yes];   }  -(void)viewdiddisappear:(bool)animated{     if (timer) {         [timer invalidate];         timer=nil;     } }     -(void)runimages{         self.custompagecontrol2.currentpage=index;         if (index==self.imagesdata.count-1) {             index=0;         }else{             index++;         }         [self tapagecontrol:self.custompagecontrol2 didselectpageatindex:index];     }          - (void)viewdidlayoutsubviews     {         [super viewdidlayoutsubviews];       }          - (void)scrollviewdidscroll:(uiscrollview *)scrollview     {         nsinteger pageindex = scrollview.contentoffset.x / cgrectgetwidth(scrollview.frame);         self.custompagecontrol2.currentpage = pageindex;         index=pageindex;     }     // example of use of delegate second scroll view respond bullet touch event     - (void)tapagecontrol:(tapagecontrol *)pagecontrol didselectpageatindex:          (nsinteger)currentindex     {         index=currentindex;         [self.scrollview scrollrecttovisible:cgrectmake(cgrectgetwidth(self.view.frame) * currentindex, 0, cgrectgetwidth(self.view.frame), cgrectgetheight(self.scrollview.frame)) animated:yes];     } 

try sdwebimage library download image server.

objective-c:

#import "uiimageview+webcache.h"  //   imageview.image = [uiimage imagenamed:[self.imagesdata objectatindex:i]]; comment line , replace bottom line  [imageview sd_setimagewithurl:[nsurl urlwithstring:[self.imagesdata objectatindex:i]              placeholderimage:[uiimage imagenamed:@"placeholder.png"]]; 

whole code

  for(int i=0; i<self.imagesdata.count;i++){         uiimageview *imageview = [[uiimageview alloc] initwithframe:cgrectmake(cgrectgetwidth(self.view.frame) * i, 0, cgrectgetwidth(self.view.frame), cgrectgetheight(self.scrollview.frame))];         imageview.contentmode = uiviewcontentmodescaleaspectfill;        [imageview sd_setimagewithurl:[nsurl urlwithstring:[self.imagesdata objectatindex:i]         placeholderimage:[uiimage imagenamed:@"placeholder.png"]];            [self.scrollview addsubview:imageview];     } 

sdwebimage source


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -