0

I have a largely populated collectionView running in my project with a collectionView cell name in Alphabetic order.I am trying to achieve a indexed collectionView like how the index function works in tableView.Please someone point me a direction where to start...

Thanks in Advance.

Joe
  • 8,868
  • 8
  • 37
  • 59

1 Answers1

0

The BDKCollectionIndexView would be a great solution to your problem.

https://github.com/kreeger/BDKCollectionIndexView

This basically create a similar indexing UI to that of the UITableview.

This is an example code posted by the creator.

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)
}

This question is also a possible duplicate: SectionIndexTitles for a UICollectionView

Community
  • 1
  • 1
Peter Zhong
  • 86
  • 1
  • 7