gpt4 book ai didi

uiviewcontroller - UICollectionViewDelegate 的奇怪行为

转载 作者:行者123 更新时间:2023-12-01 09:02:46 25 4
gpt4 key购买 nike

我有一个包含 UICollectionView 的 viewController,我在其中实现了两个委托(delegate)方法 shouldSelectItemAtIndexPath 和 didSelectItemAtIndexPath。 shouldSelect 方法按预期工作,并为每个选定的单元格调用。

不会在第一个被点击的单元格上调用 didSelect 方法,即使多次点击也是如此。但是,如果您点击第二个单元格,则会调用 didSelect 方法,但 indexPath.item 值是针对先前点击的单元格的。

例如,我点击 collectionView 中的第一个单元格,调用 shouldSelect,它的 indexPath.item 值 = 0。即使多次点击单元格,也不会调用 DidSelect。

如果我然后点击任何其他单元格,例如,collectionView 中的第 4 个单元格,将调用 shouldSelect 并且它的 indexPath.item 值 = 3。也调用了 didSelect,但它的 indexPath.item 值 = 0(之前选择的单元格)。

如果我继续选择不同的单元格,didSelect 会继续被调用,但 indexPath.item 的值始终是先前选择的项目。如果我多次点击一个单元格,didSelect 将无法调用,直到我点击另一个单元格。

有人吗?我难住了。所有其他数据源和委托(delegate)方法似乎工作正常。委托(delegate)和数据源在 Storyboard 中正确连接。

最佳答案

确保您的

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

其实不是

- (void)collectionView:(UICollectionView *)collectionView didDeSelectItemAtIndexPath:(NSIndexPath *)indexPath

(DidDeSelect 与 DidSelect)

我也有同样的问题。

关于uiviewcontroller - UICollectionViewDelegate 的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13847142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com