ios - exception in NSArrayM insertObject:atindex -
i have used 4 images in project ..while running results in:
* terminating app due uncaught exception 'nsinvalidargumentexception', reason: '* -[__nsarraym insertobject:atindex:]: object cannot nil' *** first throw call stack:
my code :
nsarray *imagenames= @[@"jake_2.png",@"jake_3.png",@"jake_4.png",@"jake_5.png "]; // additional setup after loading view, typically nib. nsmutablearray *images = [[nsmutablearray alloc] init]; (int = 0; < imagenames.count; i++) { [images addobject:[uiimage imagenamed:[imagenames objectatindex:i]]]; uiimageview *slowanimationimageview = [[uiimageview alloc] initwithframe:cgrectmake(160, 95, 86, 193)]; slowanimationimageview.animationimages = images; slowanimationimageview.animationduration = 5; [self.view addsubview:slowanimationimageview]; [slowanimationimageview startanimating]; }
you're facing issue because imagename provided in array not available in resources. check last object in array : @"jake_5.png ". there's space in it. please remove it. thats causing issue.
update :
for animation, need set after images added in imagearray. refer code , make changes :
nsmutablearray *images = [[nsmutablearray alloc] init]; (int = 0; < imagenames.count; i++) { [images addobject:[uiimage imagenamed:[imagenames objectatindex:i]]]; } slowanimationimageview.animationimages = images; slowanimationimageview.animationduration = 5; [slowanimationimageview startanimating];
hope helps...
Comments
Post a Comment