[英]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.