ios – UICollectionView indexPath.row或item,项目不稳定,跳转

ios – UICollectionView indexPath.row或item,项目不稳定,跳转,第1张

概述我创建了一个集合视图,我正在将图像加载到其中.问题我正在运行的是当我点击一个单元格来获取它的indexPath.item或indexPath.row时,数字都被搞砸了.单击第一个图像不显示任何内容,单击下一个图像将给我0.点击第三个将给我1,然后单击第二个给我一个2.这在整个视图中都会发生.我必须做错事.这是我的代码: viewDidLoad中: UICollectionViewFlowLayou 我创建了一个集合视图,我正在将图像加载到其中.问题我正在运行的是当我点击一个单元格来获取它的indexPath.item或indexPath.row时,数字都被搞砸了.单击第一个图像不显示任何内容,单击下一个图像将给我0.点击第三个将给我1,然后单击第二个给我一个2.这在整个视图中都会发生.我必须做错事.这是我的代码:

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,项目不稳定,跳转所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1006200.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存