Wednesday, June 19, 2013

NSIndexPath indexPathWithIndexes example in Objective C (iOS).

NSIndexPath indexPathWithIndexes

Creates an index path with one or more nodes.

+ (id)indexPathWithIndexes:(NSUInteger *)indexes length:(NSUInteger)length

Array of indexes to make up the index path.
Number of nodes to include in the index path.

Return Value of [NSIndexPath indexPathWithIndexes]
Index path with indexes up to length.

NSIndexPath indexPathWithIndexes example.
You might use it like this:

NSUInteger indexArr[] = {1,2,3,4};

NSIndexPath *indexPath = [NSIndexPath indexPathWithIndexes:indexArr length:4];

Example of [NSIndexPath indexPathWithIndexes].
This is probably the best you can do:

NSUInteger u_array[] = {0, 0, 0};
NSIndexPath *index_path = [NSIndexPath indexPathWithIndexes:u_array length:3];

NSIndexPath indexPathWithIndexes example.
NSIndexPath *someIndexPath = [NSIndexPath indexPathWithIndexes:newIndexes
    NSUInteger newIndexes2[[someIndexPath length]];
    [someIndexPath getIndexes:newIndexes2];

    NSUInteger len2 = sizeof(newIndexes2)/sizeof(NSUInteger);
    NSIndexPath *baseIndexPath2 = [NSIndexPath indexPathWithIndexes:newIndexes2
    NSUInteger ii;
    NSInteger start = [someIndexPath indexAtPosition:[someIndexPath length] -1];
    for (ii=start; ii<10; ii++) {
        NSIndexPath *newIndexPath2 = [baseIndexPath2 indexPathByAddingIndex:ii];
        NSLog(@"newIndexPath2 = %@", newIndexPath2);

End of NSIndexPath indexPathWithIndexes example article.