在 UIcollectionviewcell 中,数据最初并未加载到单元格中,而是加载了单元格的布局。当滚动到最后一个单元格并向后滚动时,它似乎正确地填充了数据,没有任何问题。我正在从 json 数组中获取数据。获取 json 数组后,我正在重新加载集合视图。我在情节提要中使用带有自动布局的原型单元。我尝试使用按钮操作重新加载,但在这种情况下,只有可见单元格正在更新我正在使用 flowlayout 和水平滚动这是我的 cellforitem 代码
- (UICollectionViewCell *)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ColCell" forIndexPath:indexPath];
UIImageView *img1=(UIImageView *)[cell viewWithTag:13];
img1.image = [UIImage imageNamed:@"profile_pic.png"];
if (![[[tableArray objectAtIndex:indexPath.row] valueForKey:@"img_extension"]isEqual:[NSNull null]] ) {
[img1 sd_setImageWithURL:[NSURL URLWithString:[[tableArray objectAtIndex:indexPath.row]valueForKey:@"img_extension"]] placeholderImage:nil completed:^(UIImage *image12, NSError *error, SDImageCacheType cachetype, NSURL *imageurl){
if(error)
img1 .image = nil;
else
img1 .image = image12;
CGPoint saveCenter1 = img1.center;
CGRect newFrame1 = CGRectMake(img1.frame.origin.x, img1.frame.origin.y,50, 50);
img1.frame = newFrame1;
img1.layer.cornerRadius = 50 / 2.0;
img1.center = saveCenter1;
img1.clipsToBounds = YES;
}];
}
UILabel *lbl1=(UILabel *)[cell viewWithTag:1];
UILabel *lbl2=(UILabel *)[cell viewWithTag:2];
UILabel *lbl3=(UILabel *)[cell viewWithTag:3];
UILabel *lbl4=(UILabel *)[cell viewWithTag:4];
UILabel *lbl5=(UILabel *)[cell viewWithTag:5];
UILabel *lbl6=(UILabel *)[cell viewWithTag:6];
UILabel *lbl11=(UILabel *)[cell viewWithTag:11];
UILabel *lbl12=(UILabel *)[cell viewWithTag:12];
UITextView *txtvw = (UITextView *)[cell viewWithTag:7];
lbl1.text=[[tableArray objectAtIndex:indexPath.row]valueForKey:@"strong_hand"];
lbl2.text=[[tableArray objectAtIndex:indexPath.row]valueForKey:@"athleticism"];
lbl3.text=[[tableArray objectAtIndex:indexPath.row]valueForKey:@"stick_skills"];
lbl4.text=[[tableArray objectAtIndex:indexPath.row]valueForKey:@"dodging"];
lbl5.text=[[tableArray objectAtIndex:indexPath.row]valueForKey:@"shooting"];
lbl6.text=[[tableArray objectAtIndex:indexPath.row]valueForKey:@"lacrosse"];
lbl11.text=[[tableArray objectAtIndex:indexPath.row]valueForKey:@"instructor_name"];
lbl12.text=@"INSTRUCTER";
txtvw.text = [[tableArray objectAtIndex:indexPath.row]valueForKey:@"comment"];
[cell layoutSubviews];
return cell;
}