iOS:从plist文件加载图像 [英] iOS : Load image from plist file

查看:129
本文介绍了iOS:从plist文件加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to show various images from a plist file into UIImageView , I wrote my code like this :

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

但实际上没有任何反应,我的ImageView是空的!我也有两个按钮来转发后向图像。

But actually nothing happens, and my ImageView is empty ! also I have two buttons to forward backward images .

Plist的内容:

Contents of Plist :

推荐答案

plist不正确,应该是

The plist is incorrect, it should be

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

然后将此代码添加到viewController中。确保接口imageView链接到IBOutlet。

Then add this code to your viewController.. Be sure that the Interface imageView is link to IBOutlet.

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

这篇关于iOS:从plist文件加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆