2016-07-31 19 views
0

Ich habe eine weitgehend bevölkerte collectionView in meinem Projekt mit einem collectionView-Zellenname in alphabetischer Reihenfolge.Ich versuche, eine indexierte collectionView zu erhalten, wie die Index-Funktion in tableView.Please zeigt mir eine Richtung wohin zu beginnen ...Indexed CollectionView in Swift

Dank im Voraus.

Antwort

0

Der BDKCollectionIndexView wäre eine großartige Lösung für Ihr Problem.

https://github.com/kreeger/BDKCollectionIndexView

Diese im Grunde eine ähnliche Indizierung UI zu dem dem UITableView erstellen.

Dies ist ein Beispielcode, der vom Ersteller veröffentlicht wurde.

override func viewDidLoad() { 
    super.viewDidLoad() 

    let indexWidth = 28 
    let frame = CGRect(x: collectionView.frame.size.width - indexWidth, 
     y: collectionView.frame.size.height, 
     width: indexWidth, 
     height: collectionView.frame.size.height) 
    var indexView = BDKCollectionIndexView(frame: frame, indexTitles: nil) 
    indexView.autoresizingMask = .FlexibleHeight | .FlexibleLeftMargin 
    indexView.addTarget(self, action: "indexViewValueChanged:", forControlEvents: .ValueChanged) 
    view.addSubview(indexView) 
} 

func indexViewValueChanged(sender: BDKCollectionIndexView) { 
    let path = NSIndexPath(forItem: 0, inSection: sender.currentIndex) 
    collectionView.scrollToItemAtIndexPath(path, atScrollPosition: .Top, animated: false) 
    // If you're using a collection view, bump the y-offset by a certain number of points 
    // because it won't otherwise account for any section headers you may have. 
    collectionView.contentOffset = CGPoint(x: collectionView.contentOffset.x, 
     y: collectionView.contentOffset.y - 45.0) 
} 

Diese Frage ist auch eine mögliche doppelte: SectionIndexTitles for a UICollectionView

Verwandte Themen