Posts

Showing posts with the label uicollectionview

Prepare for segue not passing data

Prepare for segue not passing data I'm working on a Swift project using firebase and I have a UICollectionViewController that has all the categories, and I need to pass the category Id to the next view, but It passes an empty string func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { let category = cnameArray[indexPath.row] let catId = category.caId func prepare(for segue: UIStoryboardSegue, sender: Any?){ if segue.identifier == "CatCity" { let cityView = segue.destination as? CityViewController cityView?.catId = catId! } } self.performSegue(withIdentifier: "CatCity", sender: self) } and in my CityViewController I have var catId = String() when I put a break point at the last line of the prepare func it gets hit and the console gets the value correctly while sitting a breakpoint at CityViewController gives me an empty var. and I checked the code and my segue name and...

Reload UICollectionView header or footer?

Reload UICollectionView header or footer? I have some data that is fetched in another thread that updates a UICollectionView's header. However, I've not found an efficient way of reloading a supplementary view such as a header or footer. I can call collectionView reloadSections: , but this reloads the entire section which is unnecessary. collectionView reloadItemsAtIndexPaths: only seems to target cells (not supplementary views). And calling setNeedsDisplay on the header itself doesn't appear to work either. Am I missing something? collectionView reloadSections: collectionView reloadItemsAtIndexPaths: setNeedsDisplay 8 Answers 8 You can also use [[_collectionView collectionViewLayout] invalidateLayout] this should really be the the accepted answer – tropicalfish Feb 1 '16 at 5:39 ...