我已经在我的项目中实现了 GmGridView。但图像在 gridViewCells 中交换。这个SO POST中的答案没有帮助。代码在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;
中的代码configureCell
,我正在使用 `dipatch_queue' 从 url 加载图像
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...";
}
}
单元格中的图像在可见单元格中向上/向下滚动时交换一次,我做错了什么?