Convert NSInteger to NSIndexpath

后端 未结 4 883
夕颜
夕颜 2020-12-14 05:55

Basically I am storing an index of an array in a NSInteger. I now need it as an NSIndexpath, I\'m struggling to see and find a way to convert my NSInteger to NSIndexpath so

4条回答
  •  感动是毒
    2020-12-14 06:30

    For an int index:

    NSIndexPath *path = [NSIndexPath indexPathWithIndex:index];
    

    Creates Index of the item in node 0 to point to as per the reference.

    To use the indexPath in a UITableView, the more appropriate method is

    NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:section];
    

提交回复
热议问题