简体   繁体   English

UICollectionView不调用didSelectItemAtIndexPath

[英]UICollectionView not calling didSelectItemAtIndexPath

I have a Collection View and has custom cells with images and labels in there. 我有一个“收藏夹视图”,并具有其中包含图像和标签的自定义单元格。 I have set my collection view as follows - 我将收藏视图设置如下:

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
flowLayout.minimumLineSpacing = 150.0f;
flowLayout.minimumInteritemSpacing = 104.0f;
flowLayout.sectionInset = UIEdgeInsetsMake(20, 20, 100, 120);

_archiveCollectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
_archiveCollectionView.frame = CGRectMake(30, 218, _archiveCollectionView.frame.size.width - 60, _archiveCollectionView.frame.size.height - 350);
_archiveCollectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_archiveCollectionView.backgroundColor = [UIColor clearColor];
_archiveCollectionView.delegate = self;
_archiveCollectionView.dataSource = self;
[self.archiveCollectionView registerNib:[UINib nibWithNibName:@"FullArchiveEditionCell" bundle:nil] forCellWithReuseIdentifier:@"MyCell"];

[_archiveCollectionView reloadData];
[self.view addSubview:_archiveCollectionView];

I have also set the following methods: 我还设置了以下方法:

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return _chosenCategoryArray.count;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [self addEditionsChildView];
}
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

However, my didSelectItemAtIndexPath never gets called when I select a cell. 但是,当我选择一个单元格时,我的didSelectItemAtIndexPath永远不会被调用。 Any help please? 有什么帮助吗?

我有一个类似的问题,原来我在两个不同的集合视图中使用相同的单元重用标识符

在头文件中,您实现了如下的UICollectionViewDelegate

@interface HAViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate>

I have the same problem. 我也有同样的问题。 And I solved by using storyboard to locate the collection cell in the collection view controller. 我通过使用情节提要板在集合视图控制器中定位集合单元来解决。 Then tick User InterAction Enabled . 然后勾选“ 用户交互已启用” I think using code to set in the UICollectionViewCell would also work. 我认为使用代码在UICollectionViewCell中进行设置也可以。 Hope it would help. 希望这会有所帮助。

Try with changing sequence as given below 尝试更改顺序,如下所示

[_archiveCollectionView reloadData];
[self.view addSubview:_archiveCollectionView];

to

[self.view addSubview:_archiveCollectionView];
[_archiveCollectionView reloadData];

Implement the below delegate method. 实现以下委托方法。

- (BOOL)collectionView:(UICollectionView *)collectionView shouldDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

And implement your 并实施您的

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
    //your selection management code 
}

and

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
    //deselection handling code 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UICollectionView didSelectItemAtIndexPath滚动 - UICollectionView didSelectItemAtIndexPath Scrolling didSelectItemAtIndexPath方法不在UICollectionView中工作 - didSelectItemAtIndexPath method not working in a UICollectionView UICollectionView didSelectitematIndexPath委托吗? - UICollectionView didselectitematindexpath delegate? 未调用 UICollectionView 的 didSelectItemAtIndexPath - didSelectItemAtIndexPath of UICollectionView is not called Swift UICollectionView:didSelectItemAtIndexPath没有响应 - Swift UICollectionView : didSelectItemAtIndexPath not responding 为什么UICollectionView在滚动其单元格的scrollView后不再调用didSelectItemAtIndexPath? - why UICollectionView not calling didSelectItemAtIndexPath any more after scrolling the scrollView of it's cells? didSelectItemAtIndexPath修改UICollectionView中的多个单元格 - didSelectItemAtIndexPath modifying multiple cells in UICollectionView 在UICollectionViewDelegate#collectionView:didSelectItemAtIndexPath中调用UICollectionView#reloadData:隐藏所有单元格 - Calling UICollectionView#reloadData in UICollectionViewDelegate#collectionView:didSelectItemAtIndexPath: hides all cells 如果用户双击,UICollectionView只调用didSelectItemAtIndexPath,当用户单击时不会调用 - UICollectionView only calling didSelectItemAtIndexPath if user double taps, will not call when user single taps didSelectItemAtIndexPath没有在ios swift中调用 - didSelectItemAtIndexPath is not calling in ios swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM