2 개의 콜렉션 뷰가 있습니다. 첫 번째 컬렉션보기의 경우 한 번에 한 셀만 표시되지만 두 번째 컬렉션보기의 경우 시간당 8 개의 셀이 표시됩니다.2 UICollectionView에서 데이터 소스와 관련된 문제가 발생했습니다.
두 번째 컬렉션보기에서 모든 것이 정상적으로 작동하지만 첫 번째 컬렉션보기는 일부 셀을 복제합니다.
아래의 코드를 사용하면 복제 된 셀에 문제가 발생할 수 있습니다. 셀이 복제되었는지는 모르겠지만 각 셀에는 이미지를 보여주는 이미지보기가 포함되어 있습니다. 따라서 해당 셀의 이미지는 100 % 중복 보증됩니다.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
GalleryCollectionViewCell *collectionViewCell = (GalleryCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"GalleryCollectionViewCell" forIndexPath:indexPath];
NSDictionary *artwork = [self.artworks objectAtIndex:indexPath.item];
[collectionViewCell loadImageWithURLString:artwork[@"image_url"]];
return collectionViewCell;
}
나는 다시 위의 통화에서 모양과 나는 또한 내 수퍼 계층 구조에서 상위 모음보기 나의 첫 컬렉션을보기 위해 인스턴스를 추가했습니다. 이제 소스 코드는 다음과 같습니다.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if ([collectionView isEqual:self.collectionViewTop])
{
GalleryCollectionViewCell *collectionViewCell = (GalleryCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"GalleryCollectionViewCell" forIndexPath:indexPath];
NSDictionary *artwork = [self.artworks objectAtIndex:indexPath.item];
[collectionViewCell loadImageWithURLString:artwork[@"image_url"]];
return collectionViewCell;
}
else
{
GalleryCollectionViewCell *collectionViewCell = (GalleryCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"GalleryCollectionViewCell" forIndexPath:indexPath];
NSDictionary *artwork = [self.artworks objectAtIndex:indexPath.item];
[collectionViewCell loadImageWithURLString:artwork[@"image_url"]];
return collectionViewCell;
}
}
콜렉션 뷰를 확인해야하는 이유는 확실하지 않지만 지금은 제대로 작동합니다. 각 셀에는 올바른 내용이 표시됩니다. 따라서 첫 번째 컬렉션보기에는 중복 된 문제가 없습니다. 추가에서
내가 코드를 추가 할 수 있습니다 어떻게 설정 이미지 : 내가 다시 전화의 콜렉션 뷰를 확인해야하는 이유 실제로 첫 컬렉션 뷰와 동일 않기 때문에
- (void)loadImageWithURLString:(NSString *)urlString
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
[self.theImageView setImageWithURLRequest:request placeholderImage:[UIImage imageNamed:@"home_screen_logo"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
[self.theImageView setImage:image];
[self.indicator stopAnimating];
[self.indicator setHidden:YES];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
}];
}
하지만, 모르는 두 번째 컬렉션보기와 같습니다. 이미지로드의 경우 AFNetworking
기능을 사용합니다.
답장을 보내 주셔서 감사합니다. autaolayout 및 크기 수업을 사용 중지했으며 지금은 영원히 작동합니다. 어떻게 영향을 미치는지는 모르겠지만 프로젝트에서 많은 문제를 야기합니다. 자동 레이아웃과 크기 클래스를 의미합니다. –