vIEwDIDLoad中:
UICollectionVIEwFlowLayout *layout = [[UICollectionVIEwFlowLayout alloc]init];layout.sectionInset = UIEdgeInsetsMake(10,20,10,20);[layout setItemSize:CGSizeMake(75,75)];self.images = [[UICollectionVIEw alloc]initWithFrame:CGRectMake(0,230,self.vIEw.frame.size.wIDth,200) collectionVIEwLayout:layout];self.images.delegate = self;self.images.dataSource = self;[self.images registerClass:[UICollectionVIEwCell class] forCellWithReuseIDentifIEr:@"cellIDentifIEr"];[self.vIEw addSubvIEw:self.images];
委托方法:
- (NSInteger)collectionVIEw:(UICollectionVIEw *)collectionVIEw numberOfItemsInSection:(NSInteger)section{ return self.imagesgallery.count; //image paths for server}- (UICollectionVIEwCell *)collectionVIEw:(UICollectionVIEw *)collectionVIEw cellForItemAtIndexPath:(NSIndexPath *)indexPath{ UICollectionVIEwCell *cell = [collectionVIEw dequeueReusableCellWithReuseIDentifIEr:@"cellIDentifIEr" forIndexPath:indexPath]; cell.layer.borderWIDth = 1; cell.layer.bordercolor = [[UIcolor whitecolor]CGcolor]; UIImageVIEw *image = [[UIImageVIEw alloc]init]; image.image = [UIImage imageWithData:[self.imagesgallery objectAtIndex:indexPath.row]]; image.frame = CGRectMake(0,cell.frame.size.wIDth,cell.frame.size.height); [cell addSubvIEw:image]; return cell;}- (voID)collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDdeselectItemAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"%d",indexPath.item);}
我不确定如何准确控制到底发生了什么.它们的编号通常如下:
0 1 23 4 5....
或者有一种特殊的方式,他们根据部分编号?他们如何填充?
解决方法 我想你缺少一个委托方法来定义你的集合视图有多少部分?- (NSInteger)numberOfSectionsInCollectionVIEw: (UICollectionVIEw *)collectionVIEw { return 1; }
一个更改的方法确实选择dIDSelect …
总结以上是内存溢出为你收集整理的ios – UICollectionView indexPath.row或item,项目不稳定,跳转全部内容,希望文章能够帮你解决ios – UICollectionView indexPath.row或item,项目不稳定,跳转所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)