转自:http://blog.csdn.net/ttf1993/article/details/44277977
要想浏览几张图片。
1》把每张图片存入每个dictionary,每个字典存一张照片的属性与名字。然后把照片字典存入NSArray。
2》初始化数组,然后得到数组,此时数组已经存满了字典。
3》拿到每个数组的里面的字典。然后显示图片到UIImageView上面。
一般加载的做法:
1》建立一个plist属性文件,然后把每个图片的属性写入进去。
2》因为软件是装在手机上的,读取图片是需要找到绝对路径,所以使用NSBuddle类。功能是得到文件的真是路径。
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"imagelist" ofType:@"plist”];
数组的建立方法就成了:
_imageData = [NSArray arrayWithContentsOfFile:path];
关于得到数组里面的字典的使用:
NSDictionary *imageDict = self.imageData[self.index];//得到字典
self.image.image = [UIImage imageNamed:imageDict[@"key"]];//使用字典
self.descLabel.text = imageDict[@"desc”]; //使用字典
并不是每次查看图片都需要加载图片。看的时候再加载
所以有了延迟加载
if(_imageData == nil) //延迟加载
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"imagelistofType:@"plist"];
_imageData = [NSArray arrayWithContentsOfFile:path];
}
下面是程序: