Загрузка изображений с Parse.com и использование их для iCarousel
Помогите мне, пожалуйста!
Я загружаю изображения с 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
2 ответа
Это старый вопрос, и я думаю, что вы уже нашли проблему с вашим кодом. Короче, если вы посмотрите внимательно:
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];
}
Я надеюсь, что это поможет вам много,
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;
}