首页 > 其他 > 详细

collectionView必须点击两次才跳转

时间:2018-11-19 13:54:37      阅读:132      评论:0      收藏:0      [点我收藏+]

  今天遇到一个很奇怪的现象:collectionView必须点击两次才能跳转。具体看代码:

-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"该项被触发");
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"选中了该项");
    self.hidesBottomBarWhenPushed = YES;
    ReadingViewController *vc = [ReadingViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}

搜了一下资料发现didDelect是取消选定,于是将该行代码删除:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"选中了该项");
    self.hidesBottomBarWhenPushed = YES;
    ReadingViewController *vc = [ReadingViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}

运行发现仍然是需要点击两次才能出发didSelect方法,查找一翻资料后发现在collectionView的初始化时多加了一行代码,将其注释就可以正常运行了:

//self.collectionView.allowsMultipleSelection = YES;

该句代码通常适用有多行选择的需求时,将其注释后,就彻底解决collectionView点击两次才跳转的问题咯。

collectionView必须点击两次才跳转

原文:https://www.cnblogs.com/sandyzhang/p/9982690.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!