Closed bobbyali closed 9 years ago
May need to force the Grid view controller to scroll to the top when returning from the settings view controller. How?
Tried making UICollectionView go to top when view controller is loaded, but it didn't help.
https://github.com/bobbyali/kidzvids2/blob/master/kidsvids/GridCollectionViewController.swift#L87
Not sure what to do now. It seems that the Collection View is out of sync with the data when the Playlist is changed. The Playlist gets changed by modifying a reference variable (currentPlaylist) in the singleton PlaylistCollection class, and this is directly accessed by the GridViewController, which should then update the number of items based on this:
https://github.com/bobbyali/kidzvids2/blob/master/kidsvids/GridCollectionViewController.swift#L120
But for some reason the UICollectionView (I think) still believes that the old number of items is available, and then crashes when it tries to access an item that is no longer there (because the new Playlist has fewer items). But I can't figure out how to force the UICollectionView to update this.
This is the line where the app actually crashes:
https://github.com/bobbyali/kidzvids2/blob/master/kidsvids/GridCollectionViewController.swift#L128
This link looks relevant, but I've tried the suggestions and they still don't work.
I've made numberOfSectionsInCollectionView
and numberOfItemsInSection
conditional on having the data loaded, but this code doesn't seem to be getting executed before the crash occurs.
isDataFetched is set to true in the ScrollView function (for when user scrolls to bottom to fetch more results) and refreshViewController() (when new playlist is loaded by view controller). It's then set to false in the delegate fetchCompleted() method.
Interestingly, the bug doesn't occur if the user never scrolls down. (i.e. they load the app, then change playlist immediately without scrolling)
Fixed. Needed a combination of the checks for isDataLoaded, and also needed some logic fixing in my code (my mistakes) when refreshing the view controller.
App crashes with this error:
fatal error: Cannot index empty buffer