如何获取尚不存在的对象的索引路径,但如果它存在,它将成为索引的下一个对象?例如,假设我有UICollectionView
这样:
即使项目x不存在,我怎样才能获得项目x的路径?例如,在这种情况下,indexpath.row
将为3。
答案 0 :(得分:1)
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:(oldIndexPath.row + 1) inSection:0];
答案 1 :(得分:0)
int itemIndex = dataSourceCount <= oldIndexPath.row + 1 ? oldIndexPath.row : oldIndexPath.row+1;
IndexPath *newIndexPath = [NSIndexPath indexPathForRow:itemIndex inSection:0];