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

use*_*063 2 nsindexpath ios uicollectionview

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

我试过这个:

 NSInteger section = [self numberOfSectionsInCollectionView:self.collectionView] - 1;
NSInteger item = [self collectionView:self.collectionView numberOfItemsInSection:section] - 1;
NSIndexPath *lastIndexPath = [NSIndexPath indexPathForItem:item inSection:section];
Run Code Online (Sandbox Code Playgroud)

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

任何建议,提前致谢。

小智 5

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

// Now just construct the index path
NSIndexPath *pathToLastRow = [NSIndexPath indexPathForRow:lastRowIndex inSection:lastSectionIndex];
Run Code Online (Sandbox Code Playgroud)