0

请帮我!

我像这样从 Parse.com 下载图像:

self.images = [[NSMutableArray alloc] init];
PFImageView *creature = [[PFImageView alloc] init];
PFQuery *query = [PFQuery queryWithClassName:@"SubCatergory"];
[query findObjectsInBackgroundWithBlock:^(NSArray *comments, NSError *error) {

    for (PFObject *comment in comments) {

        PFFile *file = [comment objectForKey:@"imageFile"];
        creature.file = file;
        creature.frame = CGRectMake(0, 0, 100, 100);
        // creature.userInteractionEnabled =YES;
        [creature loadInBackground];

        //[self.images addObject:creature];

           [self.images addObject: creature];

    }


}];

把这些放在 iCarousel 中:

-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{    

        PFImageView* img = [self.images objectAtIndex:index];
        PFImageView* imgView = [[PFImageView alloc] initWithImage:img];
        return img;

}

使用本地图像 iCarousel 效果很好。我设置了代表和数据源。我的图像数组的内容是这样的:

>", "

我得到了错误:

[PFImageView 长度]:无法识别的选择器发送到实例 0xf40e9d0

4

2 回答 2

1

这是一个老问题,我认为您已经发现您的代码存在问题。总之,如果你仔细看:

PFImageView* img = [self.images objectAtIndex:index];
PFImageView* imgView = [[PFImageView alloc] initWithImage:img];

您正在使用img,它实际上是一个UIImageView派生类,而不是UIImage您调用initWithImage.

这解释了你的崩溃。您可以安全地[self.images objectAtIndex:index]从您的carousel:viewForItemAtIndex:方法返回:

-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {

  return [self.images objectAtIndex:index];
}
于 2013-06-06T14:23:31.813 回答
0

希望对你有很大帮助

self.images = [[NSMutableArray alloc] init];
PFQuery *query = [PFQuery queryWithClassName:@"SubCatergory"];
[query findObjectsInBackgroundWithBlock:^(NSArray *comments, NSError *error) {

    for (PFObject *comment in comments) {
      PFFile *post = [comment objectForKey:@"imageFile"];
      [self.images addObject:post]; } 
    }];


-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {
          AsyncImageView *imageasy=[[AsyncImageView alloc] init];   
               [imageasy setImageURL:[NSURL URLWithString:[post url]]];
  return imageasy.image;
}
于 2013-07-30T07:22:43.333 回答