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

Replace line that causes segueing errors #7

Merged
merged 1 commit into from Jul 25, 2018

Conversation

lurein
Copy link
Contributor

@lurein lurein commented Jul 16, 2018

Replaced the range-format visibleIndices line with a stride-format as it was causing crashes when returning from segues as minVisibleIndex could become greater than maxVisibleIndex

Replaced the range-format visibleIndices line with a stride-format as it was causing crashes when returning from segues as minVisibleIndex could become greater than maxVisibleIndex
Copy link
Owner

@filletofish filletofish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contribution! 👍

@filletofish
Copy link
Owner

@lurein Have you discovered why minVisibleIndex could become greater than maxVisibleIndex?
Can you explain how to reproduce it?

@lurein
Copy link
Contributor Author

lurein commented Jul 23, 2018

@filletofish For me it occurred when I implemented a system where tapping on cards would segue to a new viewcontroller. When dismissing the Show viewcontrollers, the immediate order of the cards was disturbed as the dismissed card (which in that moment is the maxVisibleIndex) is then placed before the card that was in that moment the minVisibleIndex. Creating a similar segue system should reproduce it. It's important to note that the order of cards was pulled from a database and so it would be a different order everytime

@filletofish
Copy link
Owner

@lurein I have implemented this segue, to show viewcontroller after selecting item:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    selectedColor = collectionView.cellForItem(at: indexPath)?.backgroundColor
    performSegue(withIdentifier: "someSegue", sender: self)
  }

I have not received any errors. Maybe it is on your side, something like not calling reloadData in correct moment?

I have no idea how can dismissing of ViewController disturb wrong calculation of min / max indices. The only thing that can go wrong in calculation of min / max indices is having wrong contentOffset.x:

let minVisibleIndex = max(Int(collectionView.contentOffset.x) / Int(collectionView.bounds.width), 0)
let maxVisibleIndex = min(minVisibleIndex + maximumVisibleItems, totalItemsCount)

How does it happen in your case?

@filletofish filletofish merged commit fa148a4 into filletofish:master Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants