【问题标题】:Downloading images from Parse.com and using them for iCarousel从 Parse.com 下载图像并将其用于 iCarousel
【发布时间】:2013-05-19 17:25:51
【问题描述】:

请帮帮我!

我像这样从 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

【问题讨论】:

  • 我的图像数组的内容是这样的:>", ">",

标签: ios parse-platform icarousel


【解决方案1】:

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

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

当您调用initWithImage 时,您使用的是img,它实际上是一个UIImageView 派生类代替UIImage

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

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

  return [self.images objectAtIndex:index];
}

【讨论】:

    【解决方案2】:

    希望对你有帮助

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多