如何创建图像数组

时间:2014-02-13 08:59:40

标签: ios arrays image

i have upload the code screenshot, it has changed when i paster the code i don't know why.所有人。我从GIT下载了一个ios示例代码,我想在我的项目中使用它(ReallyBigPhotoLibrary.xcodepro)。但是这里只显示一张图片,我有很多图片,我不知道如何修改它为了适合我的项目,请帮助我。非常感谢。

//
//  PhotoDataSource.m
//  ReallyBigPhotoLibrary
//
//  Created by Kirby Turner on 9/14/10.
//  Copyright 2010 White Peak Software Inc. All rights reserved.
//

#import "PhotoDataSource.h"


@implementation PhotoDataSource

- (void)dealloc
{
   [data_ release], data_ = nil;
   [super dealloc];
}

- (id)init
{
   self = [super init];
   if (self) {
      data_ = [[NSMutableArray alloc] init];
      NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[UIImage    imageNamed:@"IMG_0694_th.jpg"], @"thumbnail", [UIImage imageNamed:@"IMG_0694.JPG"],     @"fullsize", nil];
      [data_ addObject:dict];
   }
   return self;
}

- (NSInteger)numberOfPhotos
{
   NSInteger count = 1000; [data_ count];
   return count;
}

// Implement either these, for synchronous images…
- (UIImage *)imageAtIndex:(NSInteger)index
{
   NSDictionary *dict = [data_ objectAtIndex:0];
   UIImage *image = [dict objectForKey:@"fullsize"];
   return image;
}

- (UIImage *)thumbImageAtIndex:(NSInteger)index
{
   NSDictionary *dict = [data_ objectAtIndex:0];
   UIImage *image = [dict objectForKey:@"thumbnail"];
   return image;
}


@end

1 个答案:

答案 0 :(得分:0)

更改以下方法:

- (id)init
{
   self = [super init];
   if (self) {
      data_ = [[NSMutableArray alloc] init];
      NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[UIImage    imageNamed:@"IMG_0694_th.jpg"], @"thumbnail", [UIImage imageNamed:@"IMG_0694.JPG"],     @"fullsize", nil];
      //Add all the images you have in the data. Currently you are adding only one image here.

      [data_ addObject:dict];
   }
   return self;
}

- (NSInteger)numberOfPhotos
{
   return [data_ count];
}


 - (UIImage *)imageAtIndex:(NSInteger)index
{
   NSDictionary *dict = [data_ objectAtIndex:index];
   UIImage *image = [dict objectForKey:@"fullsize"];
   return image;
}

- (UIImage *)thumbImageAtIndex:(NSInteger)index
{
   NSDictionary *dict = [data_ objectAtIndex:index];
   UIImage *image = [dict objectForKey:@"thumbnail"];
   return image;
}

希望这会有所帮助.. :)