Как получить visible IndexPath
в то время как scrolling
в collectionView
, я говорил много link1, link2 Но indexPathForCell
не поддерживается в Swift.Получить Видимый IndexPath UICollectionView в Swift
7
A
ответ
4
попробовать это
На делегатом
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
for cell in yourCollectionViewname.visibleCells() as [UICollectionViewCell] {
let indexPath = yourCollectionViewname.indexPathForCell(cell as UICollectionViewCell)
NSLog("%@", indexPath)
}
}
Choice-2
на кнопку Нажмите
var point : CGPoint = sender.convertPoint(CGPointZero, toView:yourCollectionViewname)
var indexPath =yourCollectionViewname!.indexPathForItemAtPoint(point)
Получить видны все товары
вы можете использовать indexPathsForVisibleRows
Возвращает массив индексных путей каждой идентификации видимых строк в приемнике.
- (NSArray *) indexPathsForVisibleItems;
var visible: [AnyObject] = yourCollectionViewname.indexPathsForVisibleItems
var indexpath: NSIndexPath = (visible[0] as! NSIndexPath)
12
Вы пробовали функции делегата?
public func indexPathsForVisibleItems() -> [NSIndexPath]
или
collectionView.indexPathsForVisibleItems()
они должны дать вам то, что вы хотели.
1
Swift, безопасный способ, чтобы получить видимые детали:
if let indexPaths = self.collectionView.indexPathsForVisibleItems {
//Do something with an indexPaths array.
}
0
Вы можете использовать метод из UICollectionView как:
let indexPath = NSIndexPath(item: value1, section: value2)
Смежные вопросы
- 1. Swift UICollectionView в UITableViewCell indexPath error
- 2. Swift iOS. Как я могу получить ячейки indexPath в UICollectionView
- 3. Swift: UICollectionView select cell indexPath issues
- 4. в indexPath UICollectionView в
- 5. Сброс indexPath для uicollectionview
- 6. Использование выбранной ячейки indexPath, UICollectionView
- 7. UICollectionView не прокручивается до indexPath
- 8. UICollectionView и UICollectionViewCell IndexPath error
- 9. IndexPath для выбранных клеток UICollectionView
- 10. uicollectionview scrolling change cell indexpath
- 11. получить indexpath от CollectionView, иногда получить неправильный indexPath
- 12. Swift 2.3 Ошибка IndexPath в CollectionView
- 13. Alamofire + Swift в UICollectionView
- 14. Как получить indexPath для ячейки, которая находится в центре UICollectionView
- 15. Добавить UILabel к определенному indexpath в UICollectionView
- 16. UICollectionView автоматический прокрутка к ячейке в IndexPath
- 17. UICollectionView cellForItemAtIndexPath indexPath row is no
- 18. NSIndexPath и IndexPath в Swift 3.0
- 19. prepareForSegue collectionView indexPath using swift
- 20. Segue из UICollectionView в Swift
- 21. Swift indexpath = optional (0)
- 22. Коллекция вида cellForItemAt indexPath не вызывалась (Swift)
- 23. UIcollectionview выпуск клетки Swift
- 24. indexPath не изменчивый? Swift
- 25. UICollectionview footer in swift
- 26. iOS: `UICollectionview`, как получить содержимое` contentoffset` ячейки `indexPath`
- 27. удалить раздел в indexPath swift
- 28. Граница раздела UICollectionView в Swift
- 29. Swift: бесконечные страницы в UiCollectionView
- 30. Найти indexPath в ViewController
вы хотите получать все видимые ячейки или определенную ячейку –