ios - 如何获取 uicollectionview 的最后一个索引路径?

标签 ios uicollectionview nsindexpath

我想获取 uicollectionview 的最后一个索引路径。

我试过这个:

 NSInteger section = [self numberOfSectionsInCollectionView:self.collectionView] - 1;
NSInteger item = [self collectionView:self.collectionView numberOfItemsInSection:section] - 1;
NSIndexPath *lastIndexPath = [NSIndexPath indexPathForItem:item inSection:section];

但是找不到 uicollectionview 的最后一个索引路径。

任何建议, 提前致谢。

最佳答案

NSInteger lastSectionIndex = [tableView numberOfSections] - 1;
NSInteger lastRowIndex = [tableView numberOfRowsInSection:lastSectionIndex] - 1;

// Now just construct the index path
NSIndexPath *pathToLastRow = [NSIndexPath indexPathForRow:lastRowIndex inSection:lastSectionIndex];

关于ios - 如何获取 uicollectionview 的最后一个索引路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28615052/

相关文章:

ios - Swift:如何使用 SQLite 列填充 UITableView

ios - 我如何在第 2 代 SKSpriteNode 之间等待?

ios - 如何防止将 UITableViewCell 移动到特定索引

ios - swift |没有 Storyboard的 UICollectionView 显示不正确的数据

swift - 我如何从嵌入在 UITableViewCell (Swift) 中的 UICollectionView 的单元格中分离出来?

xcode - UICollectionView reloadItemsAtIndexPaths

iphone - 在 IOS 7 中,UITextView offsetFromPosition : toPosition: always return 0 with arguments of UITextPositions returned from UITextView characterRangeAtPoint

ios - 如何将数据 CollectionViewCell 数组追加到 UIViewController 数组

arrays - 与 NSindexpathforselectedrow 混淆

ios - 多个动态原型(prototype)单元的索引路径