iPhone图像库:仅多次显示一张图像

iPhone图像库:仅多次显示一张图像,iphone,Iphone,这是我的代码roorviewcontroller.h @class PhotoDataSource; @interface RootViewController : KTThumbsViewController { PhotoDataSource *data_; } @end rootviewcontroller.m文件 @implementation RootViewController - (void)dealloc { [data_ release], da

这是我的代码roorviewcontroller.h

 @class PhotoDataSource;
 @interface RootViewController : KTThumbsViewController 
 {
     PhotoDataSource *data_;
 }
 @end
rootviewcontroller.m文件

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

 - (PhotoDataSource *)data
 {
   if (data_) {
      return data_;
     }

    data_ = [[PhotoDataSource alloc] init];
   return data_;
 }

- (void)viewDidLoad 
 {
  [super viewDidLoad];

 [self setDataSource:[self data]];
   [self setTitle:[NSString stringWithFormat:@"%i Photos", [data_ numberOfPhotos]]];

     UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back", @"Back button title") style:UIBarButtonItemStylePlain target:nil action:nil];
  [[self navigationItem] setBackBarButtonItem:backButton];
[backButton release];
 }
.h文件

 @interface PhotoDataSource : NSObject <KTPhotoBrowserDataSource>
 { 
 NSMutableArray *data_;
 sqlite3 *UsersDB;
 NSString *databasePath;
 NSString *coun;
 NSMutableArray *sa;
 NSString *fullPathToFile;
 }
@property (nonatomic, assign) NSString *coun;
@end

我执行了这段代码并成功运行。但它显示的是单一的图像。我在iphonesdk路径中存储了多个图像。它并没有显示所有的图像。我想显示所有图像。但这段代码只显示db路径中的一个图像,和同一个图像的数量一样多。如何显示使用此代码自定义的所有图像。任何人都可以帮助我,请提前表示感谢。

仔细看看您在imageAtIndex:和thumbImageAtIndex中所做的工作:-您正在调用objectAtIndex:0,因此您将只看到到处使用的第一个图像。在这两种情况下都使用objectAtIndex:index

换言之,这两种方法应理解为:

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

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

谢谢你的回复。我试过这个。此行中的控制台错误NSDictionary*dict=[data\uObjectAtIndex:index];它不能正常工作。它多次只显示一个图像
- (UIImage *)imageAtIndex:(NSInteger)index
{
    NSDictionary *dict = [data_ objectAtIndex:index];  // using index here
    UIImage *image = [dict objectForKey:@"fullsize"];
    return image;
}

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