简体   繁体   中英

IndexPath for first element in CollectionView

How should look IndexPath for first position in CollectionView? I need to move certain element to first position:

collectionView.moveItem(at: collectionView.indexPath(for: cell)!,
                                        to: *????*))

Use IndexPath(item: Int, section: Int) . In this case it will be

IndexPath(item: 0, section: 0)

You can even define a zero static variable as CGRect and other are doing

extension IndexPath {
    static let zero = IndexPath(item: 0, section: 0)
}

and use it as

collectionView.moveItem(at: collectionView.indexPath(for: cell)!, to: .zero))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM