大佬教程收集整理的这篇文章主要介绍了cellForItemAtIndexPath,sizeForItemAtIndexPath,insetForSectionAtIndex未被调用iOS,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
单元的标识符是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]; } }
任何建议将不胜感激.谢谢.
以上是大佬教程为你收集整理的cellForItemAtIndexPath,sizeForItemAtIndexPath,insetForSectionAtIndex未被调用iOS全部内容,希望文章能够帮你解决cellForItemAtIndexPath,sizeForItemAtIndexPath,insetForSectionAtIndex未被调用iOS所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。