셀에서 UIImage 객체를 사용할 때 수집보기를 삭제할 수 없었습니다.
-
20-12-2019 - |
문제
여러 번 반복 한 후에 충돌이 발생한 후이 코드를 실행하는 데 어려움을 겪고 있습니다. 의도 된 동작은 배열에서 컬렉션보기에 이미지를 표시하기 만하면됩니다. 배열의 모든 개체를 주석 처리하면 빈 컬렉션보기로 실행됩니다. logo.png가 존재하며 드롭 다운을 통해 앱의 다른 부분에 올바르게로드 될 수 있습니다. 대리인과 데이터 소스가 제대로 자체로 설정되어 있습니다. 컬렉션보기에는 이미지보기가있는 단일 셀이 표시됩니다 (100로 태그가 지정되어 있지 않음). 이미지보기 대신 레이블이있는 경우 배열의 모든 객체와 충돌이 발생합니다.
디버깅 출력은
입니다.는 종류의 견해를 억제 할 수 없었습니다 : 식별자 셀을 가진 UICollectionElementKindCell -
식별자에 대한 NIB 또는 클래스를 등록하거나 스토리 보드에 프로토 타입 셀을 연결
관련 코드는 다음과 같습니다.
ViewController.m
#import "demo_frameworkViewController.h"
@interface demo_frameworkViewController ()
@end
@implementation demo_frameworkViewController {
NSMutableArray *imageArray;
}
@synthesize imageArray;
- (void)viewDidLoad
{
imageArray = [[NSMutableArray alloc] init];
[imageArray addObject:[UIImage imageNamed:@"logo.png"]];
[imageArray addObject:[UIImage imageNamed:@"logo.png"]];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark Collection View Methods
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return [self.imageArray count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
UIImageView *imageDemo = (UIImageView *)[cell viewWithTag:100];
imageDemo.image =[imageArray objectAtIndex:indexPath.row];
[cell.layer setBorderWidth:2.0f];
[cell.layer setBorderColor:[UIColor whiteColor].CGColor];
return cell;
}
@end
.
ViewController.h
#import <UIKit/UIKit.h>
@interface demo_frameworkViewController : UIViewController <UINavigationControllerDelegate, UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, retain) NSArray *imageArray;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
. 해결책
디버깅 출력은 '셀'이라는 셀을 찾을 수 없음을 의미합니다.스토리 보드에서 UICollectionViewCell의 Collection Reusable View
값을 '셀'으로 설정하여 UICollectionView가
제휴하지 않습니다 StackOverflow