iCarousel + Parse:从PFObject加载异步图像

时间:2014-02-07 21:39:53

标签: ios7 parse-platform icarousel

我试图使用parse(parse.com,pfoject)对象填充iCarousel但没有成功。

我找不到任何如何做的例子,所以我在这里问的原因......

- (void)viewDidLoad
{
    [super viewDidLoad];

_items = [NSMutableArray array];

PFQuery *query = [PFQuery queryWithClassName:@"testUser"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        // The find succeeded. The first 100 objects are available in objects
        [_items addObjectsFromArray:objects];

    } else {
        // Log details of the failure
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
}];


//configure carousel
_carousel.type = iCarouselTypeRotary;

//_carousel.viewpointOffset = CGSizeMake(0.0f, 100.0f);
[_carousel setContentOffset:CGSizeMake(0.0f, -60.0f)];

}

在viewForItemAtIndex:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    //create new view if no view is available for recycling
    if (view == nil)
    {
        view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300.0f, 300.0f)];
    }

PFObject *eachObject = [_items objectAtIndex:index];
PFFile *theImage = [eachObject objectForKey:@"image"];
NSData *imageData = [theImage getData];
UIImage *image = [UIImage imageWithData:imageData];

((UIImageView *)view).image = image;
view.contentMode = UIViewContentModeCenter;

return view;

}

请帮忙吗? : - (

1 个答案:

答案 0 :(得分:0)

在viewDidLoad中,在

之后
   [_items addObjectsFromArray:objects];

 [_carousel reloadData];

否则,在将项目添加到数组后,轮播将不会更新,因此您仍然会看到空的轮播。