Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is the UICollectionView done loading completely?

Tags:

swift

How do I know that the UICollectionView has been loaded completely? I'm trying to reproduce this solution in Swift, but I'm having trouble reading the Obj-C. Can someone help?

like image 776
Grant Park Avatar asked Aug 09 '15 19:08

Grant Park


People also ask

How does UICollectionView work?

UICollectionView makes adding custom layouts and layout transitions, like those in Photos, simple to build. You're not limited to stacks and grids because collection views are customizable. You can use them to make circle layouts, cover-flow style layouts, Pulse news style layouts and almost anything you can dream up!

What is UICollectionView flow layout?

A layout object that organizes items into a grid with optional header and footer views for each section.

What is the difference between Uitableview and UICollectionView?

Tableiw is a simple list, which displays single-dimensional rows of data. It's smooth because of cell reuse and other magic. 2. UICollectionView is the model for displaying multidimensional data .


1 Answers

SWIFT 3: version of @libec's answer

override func viewDidLoad() {
    super.viewDidLoad()
    collectionView.addObserver(self, forKeyPath: "contentSize", options: NSKeyValueObservingOptions.old, context: nil)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    collectionView.removeObserver(self, forKeyPath: "contentSize")
}

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
    if let observedObject = object as? UICollectionView, observedObject == collectionView {
        print("done loading collectionView")
    }
}
like image 92
Salil Junior Avatar answered Sep 24 '22 03:09

Salil Junior