OStack程序员社区-中国程序员成长平台

标题: iphone - iOS : Load image from plist file [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 21:13
标题: iphone - iOS : Load image from plist file

我正在尝试将 plist 文件中的各种图像显示到 UIImageView 中,我这样编写代码:

NSDictionary *picturesDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource"hotos" ofType"plist"]];    
    imageArray = [picturesDictionary objectForKey"hotosArray"];
    PhotosInAlbum.image = [UIImage imageWithContentsOfFile:[imageArray objectAtIndex:1]];

但实际上什么也没发生,我的 ImageView 是空的!我还有两个按钮可以向前向后图像。

Plist 的内容: enter image description here



Best Answer-推荐答案


plist不正确,应该是

Root ---- Dictionary
     PhotosArray ----- Array
         Item 0   ------ String -- Beach.jpg

然后将此代码添加到您的 viewController.. 确保 Interface imageView 链接到 IBOutlet。

NSDictionary *picturesDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource"hotos" ofType"plist"]];     
NSArray *imageArray = [picturesDictionary objectForKey"hotosArray"]; 
PhotosInAlbum.image = [UIImage imageNamed:[imageArray objectAtIndex:0]];

关于iphone - iOS : Load image from plist file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10846620/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4