[英]how to check if i can read image from bundle using NSError?
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? 并且我想将NSError
添加到此代码中...如何确定我的图像将被加载而不导致应用程序崩溃? ( using NSError
) 10x (使用NSError
)10x
Check if imageNamed:
returns nil
. 检查imageNamed:
返回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];
}
}
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");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.