获取“下一个”索引的NSIndexPath?

时间:2014-01-01 22:04:55

标签: ios iphone objective-c

如何获取尚不存在的对象的索引路径,但如果它存在,它将成为索引的下一个对象?例如,假设我有UICollectionView这样:

  • 第1项
  • 第2项
  • 第3项
  • item x

即使项目x不存在,我怎样才能获得项目x的路径?例如,在这种情况下,indexpath.row将为3。

2 个答案:

答案 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];