Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-11267] KeyValueObserving on isSelected for UICollectionViewCell called even after retuning false in the UICollectionViewDelegate method shouldSelectItem #3987

Open
swift-ci opened this issue Aug 7, 2019 · 2 comments

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Aug 7, 2019

Previous ID SR-11267
Radar None
Original Reporter deepakbadiger@gmail.com (JIRA User)
Type Bug
Environment

XCode Version 10.2 (10E125)

Model Name: MacBook Pro

Model Identifier: MacBookPro14,3

Processor Name: Intel Core i7

Processor Speed: 2.8 GHz

Number of Processors: 1

Total Number of Cores: 4

L2 Cache (per Core): 256 KB

L3 Cache: 6 MB

Hyper-Threading Technology: Enabled

Memory: 16 GB

Boot ROM Version: 194.0.0.0.0

SMC Version (system): 2.45f0

Serial Number (system): XXXXX

Hardware UUID: XXXXX

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 58b9f49efe7fb0b26557067ce54ea7fd

Issue Description:

I have a UICollectionView and i have added a KVO on UICollectionViewCell item

internal class DayCollectionCell: UICollectionViewCell {

... some code
 
observation = self.observe(\DayCollectionCell.isSelected, options: [.initial, .new, .old], changeHandler: selectionDidChange)

... some code

}

based on certain conditional validation, i'm returning false from the shouldSelectItem delegate method on UICollectionView. This delegate method is called when i select an item on the UICollectionView.

Also, strangely, this method is called after the observer is called. I would expect observer on isSelected to be called based on my boolean value in shouldSelectItem - as this event will actually advise whether the item should be selected or not.

Actual Result:

Irrespective of whether i return true / false, the observer is always called.

Expected Result:

It should fire the observer only if i return true from shouldSelectItem.

@belkadan
Copy link

cc @millenomi

@millenomi
Copy link
Contributor

KVO, and the Swift overlay, are not responsible for when observations fire. This should likely be a bug you file with bugreport.apple.com rather than here.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants