2014-02-13 155 views
0

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 
+0

您的可變數組只有一個對象。你想如何製作以適合你的項目? – jailani

+0

please。我該怎麼做。請幫助我 – smallgood

+0

從哪裏得到圖像。? – Akhilrajtr

回答

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; 
} 

希望這有助於.. :)

+0

非常感謝,我會嘗試。 – smallgood

+0

你解決了這個問題嗎? – Rashad

+0

我正在嘗試... – smallgood