ios – 奇怪的UICollectionView选择行为

ios – 奇怪的UICollectionView选择行为,第1张

概述我正在使用UICollectionView来显示一个菜单,并且这些项目正以非常奇怪的方式进行选择. 这是我填写的静态数据: self.menuItems = @[@{@"text" : @"First", @"image" : @"180-stickynote.png"}, @{@"text" : @"Second", @"image" : @"180-sti 我正在使用UICollectionVIEw来显示一个菜单,并且这些项目正以非常奇怪的方式进行选择.

这是我填写的静态数据:

self.menuItems = @[@{@"text" : @"First",@"image" : @"180-stickynote.png"},@{@"text" : @"Second",@{@"text" : @"Third",@{@"text" : @"Fourth",@{@"text" : @"Fifth",@{@"text" : @"Sixth",@"image" : @"180-stickynote.png"}];

和单元格提供程序,其中自定义子类附加到原型单元格,并具有UILabel和UIImageVIEw:

- (UICollectionVIEwCell *)collectionVIEw:(UICollectionVIEw *)collectionVIEw cellForItemAtIndexPath:(NSIndexPath *)indexPath{    CUMenuCollectionVIEwCell *cell = [collectionVIEw dequeueReusableCellWithReuseIDentifIEr:@"MenuCell" forIndexPath:indexPath];    NSDictionary *cellinfo = [self.menuItems objectAtIndex:indexPath.row];    cell.imageVIEw.image = [UIImage imagenamed:[cellinfo valueForKey:@"image"]];    cell.label.text = [cellinfo valueForKey:@"text"];    return cell;}

这里是选择行方法,记录标题和项目的行(它们都在第0部分):

- (voID)collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDdeselectItemAtIndexPath:(NSIndexPath *)indexPath{    NSLog(@"%@: %d",[[self.menuItems objectAtIndex:indexPath.row] valueForKey:@"text"],indexPath.row);}

最后,我的菜单的屏幕截图:

这是从第一到第六,从第六到第一(第一,第二,第三,第四,第五,第六,第一)的项目的日志(共12个抽头,注意,第一个水龙头甚至没有注册,第六个水龙头也没有):

------------------------------------- FirsT TAP ON FirsT HERE2013-02-13 19:38:37.343 App[1383:c07] First: 0  // second tap,on Second2013-02-13 19:38:38.095 App[1383:c07] Second: 1 // third tap,on Third2013-02-13 19:38:38.678 App[1383:c07] Third: 2  // fourth tap,on Fourth2013-02-13 19:38:39.375 App[1383:c07] Fourth: 3 // fifth tap,on Fifth2013-02-13 19:38:40.167 App[1383:c07] Fifth: 4  // so on2013-02-13 19:38:41.751 App[1383:c07] Sixth: 5------------------------------------- SECOND TAP ON SIXTH HERE2013-02-13 19:38:42.654 App[1383:c07] Fifth: 42013-02-13 19:38:43.318 App[1383:c07] Fourth: 32013-02-13 19:38:44.495 App[1383:c07] Third: 22013-02-13 19:38:45.071 App[1383:c07] Second: 1
解决方法 这是因为您使用dIDdeselectItemAtIndexPath:方法而不是dIDSelectItemAtIndexPath :.一个容易的错误,特别是当你使用代码完成,当你输入它. 总结

以上是内存溢出为你收集整理的ios – 奇怪的UICollectionView选择行为全部内容,希望文章能够帮你解决ios – 奇怪的UICollectionView选择行为所遇到的程序开发问题。

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

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

原文地址:https://54852.com/web/1097983.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存