2016-07-31 50 views
0

我有一个主要人口的CollectionView在我与字母order.I一个的CollectionView单元名称项目运行想实现一个索引的CollectionView类的指数函数tableView.Please别人是如何工作的指向我一个方向,其中开始...索引的CollectionView斯威夫特

在此先感谢。

回答

0

的BDKCollectionIndexView将是一个伟大的解决您的问题。

https://github.com/kreeger/BDKCollectionIndexView

这基本上创建一个类似的索引UI来了的UITableView的。

这是张贴由创建者的示例代码。

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

这个问题也有可能重复: SectionIndexTitles for a UICollectionView