Get Visible IndexPath UICollectionView in Swift
Have you tried delegate function?
public func indexPathsForVisibleItems() -> [NSIndexPath]
or
collectionView.indexPathsForVisibleItems()
these must give you what you wanted.
Swift, safer way to get visible Items:
if let indexPaths = self.collectionView.indexPathsForVisibleItems { //Do something with an indexPaths array.}
try this
On delegate
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {for cell in yourCollectionViewname.visibleCells() as [UICollectionViewCell] { let indexPath = yourCollectionViewname.indexPathForCell(cell as UICollectionViewCell) NSLog("%@", indexPath)}}
Choice-2
on Button Click
var point : CGPoint = sender.convertPoint(CGPointZero, toView:yourCollectionViewname)var indexPath =yourCollectionViewname!.indexPathForItemAtPoint(point)
Get visible All Items
you can use indexPathsForVisibleRows
Returns an array of index paths each identifying a visible row in the receiver.
- (NSArray *)indexPathsForVisibleItems;
var visible: [AnyObject] = yourCollectionViewname.indexPathsForVisibleItemsvar indexpath: NSIndexPath = (visible[0] as! NSIndexPath)