简体   繁体   English

以编程方式在 UIImageview 中设置图像

[英]set image in UIImageview Programmatically

I have build one application.我已经构建了一个应用程序。 In this application I set image in UIImageView at the button's clicked action.在这个应用程序中,我在按钮的单击操作中设置了 UIImageView 中的图像。 and next time clicked on button the image is changed, this operation is successfully done.并且下次单击按钮图像被更改,此操作成功完成。 but after sometime the button is clicked properly but the image is not changed in UIIMageView and print following message on console:但一段时间后,该按钮被正确单击,但 UIIMageView 中的图像未更改,并在控制台上打印以下消息:

ImageIO: CGImageRead_mapData 'open' failed '/Users/UserName/Library/Application Support/iPhone Simulator/4.2/Applications/02FE7A45-261F-4AED-AB37-592A228876FC/appName.app/imageName.png' error = 24 (Too many open files) ImageIO:CGImageRead_mapData 'open' failed '/Users/UserName/Library/Application Support/iPhone Simulator/4.2/Applications/02FE7A45-261F-4AED-AB37-592A228876FC/appName.app/imageName.png' 错误 = 24(打开的太多文件)

i can use following code for set the image in UIImageView我可以使用以下代码在 UIImageView 中设置图像

    NSString *path = [[NSBundle mainBundle] pathForResource:strQue ofType:@"png"];

UIImage *img = [[UIImage alloc] initWithContentsOfFile:path];

    [img1 setImage:img];

where img1 is the object of UIImageview and strQue is the name of the image其中 img1 是 UIImageview 的 object 和 strQue 是图像的名称

ImageIO: CGImageRead_mapData 'open' failed '/Users/UserName/Library/Application Support/iPhone Simulator/4.2/Applications/02FE7A45-261F-4AED-AB37-592A228876FC/appName.app/imageName.png' error = 24 (Too many open files) ImageIO:CGImageRead_mapData 'open' failed '/Users/UserName/Library/Application Support/iPhone Simulator/4.2/Applications/02FE7A45-261F-4AED-AB37-592A228876FC/appName.app/imageName.png' 错误 = 24(打开的太多文件)

This is just a wild stab in the dark here, but I'm guessing your app is opening too many files.这只是在这里黑暗中的狂野刺,但我猜您的应用程序打开了太多文件。

it seems that your path in variable strQue may be wrong..print log for that variable and check the path when it crashed....似乎您在变量 strQue 中的路径可能是错误的..打印该变量的日志并在它崩溃时检查路径....

one other possibility that if you have that three lines codes in for loop that may also cause this type of error...另一种可能性是,如果你在 for 循环中有这三行代码,也可能导致这种类型的错误......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM