iCarousel + Parse:从 PFObject 加载异步图像
Posted
技术标签:
【中文标题】iCarousel + Parse:从 PFObject 加载异步图像【英文标题】:iCarousel + Parse: Loading Async Images from PFObject 【发布时间】:2014-02-07 21:39:53 【问题描述】:我正在尝试使用 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】:在viewDidLoad之后
[_items addObjectsFromArray:objects];
放
[_carousel reloadData];
否则在将项目添加到数组后轮播将不会更新,因此您仍然会看到一个空的轮播。
【讨论】:
以上是关于iCarousel + Parse:从 PFObject 加载异步图像的主要内容,如果未能解决你的问题,请参考以下文章
iCarousel 从 NSMutableArray 加载 UIViews