Convert NSInteger to NSIndexpath

后端 未结 4 882
夕颜
夕颜 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:41

    Use below methods of NSIndexPath class.

    + (id)indexPathWithIndex:(NSUInteger)index;
    + (id)indexPathWithIndexes:(NSUInteger *)indexes length:(NSUInteger)length;
    - (id)initWithIndex:(NSUInteger)index
    

    Use as below and also Don't forget to release myIndexPath object after using.

    NSIndexPath *myIndexPath = [[NSIndexPath alloc] initWithIndex:[myIntObj intValue]];
    

提交回复
热议问题