저는 셀 재정렬을 허용하는 UICollectionViewFlowLayout
의 사용자 정의 하위 클래스를 사용하고 있습니다. 소스 코드 here.UICollectionView 셀을로드하지 않았습니다.
내가 겪고있는 문제는 컬렉션 뷰용으로 만든 nib 파일을 등록하고 올바른 식별자를 사용 했음에도 불구하고로드되지 않는다는 것입니다. 다음은 관련 코드 스 니펫입니다.
이 뷰 컨트롤러 .m
파일에 있습니다 :
- (void)loadView
{
self.reorderLayout = [[LXReorderableCollectionViewFlowLayout alloc] init];
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero
collectionViewLayout:self.reorderLayout];
UINib *nib = [UINib nibWithNibName:@"CatagoryViewCell" bundle:nil];
[self.collectionView registerNib:nib forCellWithReuseIdentifier:@"CatagoryViewCellID"];
self.collectionView.dataSource = self;
self.collectionView.delegate = self;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
Catagory *c = [[[CatagoryStore defaultStore] allCatagories]
objectAtIndex:[indexPath item]];
CatagoryViewCell *cell = (CatagoryViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"CatagoryViewCellID" forIndexPath:indexPath];
[cell setController:self];
[[cell nameLabel] setText:c.title];
return cell;
}
이 내가 펜촉을 참조하는 두 장소입니다. 내가 유사한 코드 원래 UICollectionViewFlowLayout
클래스를 사용하여 시도하고 작동
:
이 그것을 시뮬레이터 및 장치의 모습입니다 : 여기
셀 펜촉입니다 벌금. 어떤 통찰력이라도 대단히 감사합니다![collectionView registerClass:[YourCollectionViewCell class] forCellWithReuseIdentifier:@"YourCollectionViewCell"];
그리고 마지막으로
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
// Setup cell identifier
static NSString *cellIdentifier = @"YourCollectionViewCell";
YourCollectionViewCell *cell = (YourCollectionViewCell *)[cvArticles dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
}
: 당신이 드 콜렉션 뷰 추가 기능을 가지고있는 클래스
-(id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
NSString *cellNibName = @"YourCollectionViewCell";
NSArray *resultantNibs = [[NSBundle mainBundle] loadNibNamed:misVentasCellNibName owner:nil options:nil];
if ([resultantNibs count] < 1) {
return nil;
}
if (![[resultantNibs objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]]) {
return nil;
}
self = [resultantNibs objectAtIndex:0];
}
return self;
}
그런 다음 CollectionViewCell.m 안쪽이 "initWithFrame"방법과
ARC를 사용하고 있습니까? – Jorge
@Jorge 그래 난입니다 – isal
이 게시물을 살펴보십시오 http://stackoverflow.com/questions/14466959/create-uicollectionviewcell-subclass-with-xib – neaGaze