I have implemented GmGridView in my project. but images are swapping in gridViewCells. the answer in this SO POST didn't helped. Code in cellForItemAtIndex
CGSize size = [self GMGridView:gridView sizeForItemsInInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
GMGridViewCell *cell = (GMGridViewCell *)[gridView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[GMGridViewCell alloc] initWithFrame:CGRectMake( 0, 0, size.width, size.height)];
cell.reuseIdentifier = @"Cell";
[[NSBundle mainBundle] loadNibNamed:@"HomeCustomCell" owner:self options:nil];
[cell addSubview:_homeViewCell];
}
[cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
//method to set data
[self configureCell:cell inGMGridView:gridView atIndexPath:index];
return cell;
Code in configureCell
, I'm using `dipatch_queue' to load images from urls
SNHomeCustomCell *customCell = (SNHomeCustomCell *)[cell viewWithTag:100];
CGSize size = [self GMGridView:gmGridView sizeForItemsInInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
customCell.frame = CGRectMake(0, 0, size.width, size.height);
NSUInteger nodeCount = self.productArray.count;
if (nodeCount > 0) {
customCell.productImage.image = nil;
PFObject *object = self.productArray[index];
if (object) {
customCell.productName.text = object[@"name"];
customCell.productPrice.text = [NSString stringWithFormat:@"$%@", object[@"price"]];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:object[@"imageUrl"]]]];
dispatch_async(dispatch_get_main_queue(), ^{
[customCell.productImage setImage:image];
});
});
} else {
customCell.productName.text = @"Loading...";
customCell.productPrice.text = @"Loading...";
}
}
the image's in cells are swapping once in scroll up/down in the visible cell, what am I doing wrong?