Reputation: 726
i need to check if image was read.. i have this code:
[self setView];
-(void)setView{
for(int i = self.firstNumberOfImages; i <= self.lastNumberOfImages; i++)
{
UIImage* image = [UIImage imageNamed:[NSString stringWithFormat:@"%@%d.%@",self.imageName,i,self.imageType]];
NSLog(@"%d",i);
[imgArray addObject:image];
}
......
}
and i want to add NSError
to this code... how i can be sure that my images will be load without the app will crash? ( using NSError
)
10x
Upvotes: 0
Views: 58
Reputation:
Check the Below code
for(int i = self.firstNumberOfImages; i <= self.lastNumberOfImages; i++)
{
UIImage* image = [UIImage imageNamed:[NSString
stringWithFormat:@"%@%d.%@",self.imageName,i,self.imageType]];
NSLog(@"%d",i);
@try{
[imgArray addObject:image];
}
@catch(exception e)
{
NSLog(@"ERROR");
}
}
Upvotes: 0
Reputation: 40211
Check if imageNamed:
returns nil
.
for(int i = self.firstNumberOfImages; i <= self.lastNumberOfImages; i++)
{
UIImage* image = [UIImage imageNamed:[NSString
stringWithFormat:@"%@%d.%@",self.imageName,i,self.imageType]];
NSLog(@"%d",i);
if (image) {
[imgArray addObject:image];
}
}
Upvotes: 1