
单元的标识符是photoCell,类是JLTPhotoCell.
- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; _thumbnails = [[NSArray alloc]init]; // its declared,don't worry about this _thumbnails = [[LADataModelController getSingleton] getAllSignatures]; UICollectionVIEwFlowLayout *layout = [[UICollectionVIEwFlowLayout alloc] init]; [layout setItemSize:( CGSizeMake(50,50))]; [_collectionVIEw setCollectionVIEwLayout:layout]; self.collectionVIEw.delegate = self; self.collectionVIEw.dataSource = self; [_collectionVIEw registerClass:[JLTPhotoCell class] forCellWithReuseIDentifIEr:@"photoCell"]; [self.vIEw addSubvIEw:self.collectionVIEw]; self.collectionVIEw.allowsSelection = true; }- (NSInteger)collectionVIEw:(UICollectionVIEw *)vIEw numberOfItemsInSection:(NSInteger)section{ NSLog(@"count %i",_thumbnails.count); return _thumbnails.count;}- (NSInteger)numberOfSectionsInCollectionVIEw: (UICollectionVIEw *)collectionVIEw{ return 1;}- (UICollectionVIEwCell *)collectionVIEw:(UICollectionVIEw *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath{ if (_thumbnails.count > 0) { JLTPhotoCell *cell = [cv dequeueReusableCellWithReuseIDentifIEr:@"photoCell" forIndexPath:indexPath]; NSData *thumbnailData = ((LASignature*)[_thumbnails objectAtIndex:indexPath.row]).signatureImage; UIImage* thumbnailImage = [UIImage imageWithData:thumbnailData]; [cell setthumbnail:thumbnailImage]; NSLog(@"image:%@",thumbnailImage); if (!_buttonSelect.hIDden) { [cell performSelected:FALSE]; } return cell; } return nil;}#pragma mark UICollectionVIEwDelegate Methods-(voID) collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDSelectItemAtIndexPath:(NSIndexPath *)indexPath{ _lastSelectedSign = [_thumbnails objectAtIndex:indexPath.row]; if (!self.buttonSelect.hIDden) { JLTPhotoCell *cell = (JLTPhotoCell *)[_collectionVIEw cellForItemAtIndexPath:indexPath]; cell.selected = FALSE; } else { [_selectedImages addobject:[_thumbnails objectAtIndex:indexPath.row]]; JLTPhotoCell *cell = (JLTPhotoCell *)[_collectionVIEw cellForItemAtIndexPath:indexPath]; [cell performSelected:TRUE]; // _buttonDelete.enabled = _selectedImages.count > 0; }}-(voID) collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDdeselectItemAtIndexPath:(NSIndexPath *)indexPath{ [_selectedImages removeObject:[_thumbnails objectAtIndex:indexPath.row]]; JLTPhotoCell *cell = (JLTPhotoCell *)[_collectionVIEw cellForItemAtIndexPath:indexPath]; [cell performSelected:FALSE]; _buttonDelete.enabled = _selectedImages.count > 0;}#pragma mark - UICollectionVIEwDelegateFlowLayout-(CGSize) collectionVIEw:(UICollectionVIEw *)collectionVIEw layout:(UICollectionVIEwLayout *)collectionVIEwLayout sizeforItemAtIndexPath:(NSIndexPath *)indexPath{ return CGSizeMake(50,50) ;}-(UIEdgeInsets) collectionVIEw:(UICollectionVIEw *)collectionVIEw layout:(UICollectionVIEwFlowLayout *)collectionVIEwLayout insetForSectionAtIndex:(NSInteger)section{ collectionVIEwLayout.minimumInteritemSpacing=1; collectionVIEwLayout.minimumlinespacing =2; return UIEdgeInsetsMake(1,1,1);}jltPhotoCell Class-(voID) setthumbnail:(UIImage *) thumbnail{ [self setthumbnail:thumbnail anDWithSize:(CGSizeMake(50,50))];}-(voID) setthumbnail:(UIImage *) thumbnail anDWithSize:(CGSize) size{ UIImageVIEw *thumbImageVIEw = [[UIImageVIEw alloc] initWithImage:thumbnail]; thumbImageVIEw.frame = CGRectMake(0,size.wIDth,size.height); thumbImageVIEw.userInteractionEnabled = YES; [self.contentVIEw addSubvIEw:thumbImageVIEw];}-(voID) performSelected:(bool)selected{ if (selected) { UIImageVIEw *deleteImageVIEw = [[UIImageVIEw alloc] initWithImage:[UIImage imagenamed:@"delete"]]; deleteImageVIEw.frame = CGRectMake(self.contentVIEw.frame.size.wIDth - 35,3,32,32); deleteImageVIEw.tag = 123; [self.contentVIEw addSubvIEw:deleteImageVIEw]; } else { UIVIEw *v = [self.contentVIEw vIEwWithTag:123]; v.hIDden = YES; [self.contentVIEw bringSubvIEwToFront:v]; [v removeFromSupervIEw]; }} 任何建议将不胜感激.谢谢.
解决方法 作为@highlycaffeinated我遇到了这个问题.但是调用invalIDateLayout对我来说不起作用.但是,在数据源工作之后分配代理.
我变了:
self.collectionVIEw.delegate = self;self.collectionVIEw.dataSource = self;
有:
self.collectionVIEw.dataSource = self;self.collectionVIEw.delegate = self;总结
以上是内存溢出为你收集整理的cellForItemAtIndexPath,sizeForItemAtIndexPath,insetForSectionAtIndex未被调用iOS全部内容,希望文章能够帮你解决cellForItemAtIndexPath,sizeForItemAtIndexPath,insetForSectionAtIndex未被调用iOS所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)