views:

10064

answers:

3

The class method to create an index path with one or more nodes is:

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

How do we create the "indexes" required in the first parameter?

The documentation listed it as Array of indexes to make up the index path but it is expecting a (NSUinteger *).

To create an index path of 1.2.3.4, is it simply an array of [1,2,3,4] ?

+4  A: 

You assumption is correct. It's as simple as a C array of NSUInteger. The length parameter is the number of elements in the indexes array.

Arrays in C are often identified as a pointer (in this case NSUInteger *) with a length parameter or a known terminator such as \0 for C strings (which is just a char array).

Giao
+16  A: 

You are correct. You might use it like this:

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

NSIndexSet *indexSet = [NSIndexPath indexPathWithIndexes:indexArr length:4];
Barry Wark
sorry for newbie question: do i need to [indexSet release] after use?
Steve
@Steve Not in this case. You will find the answer to this an all Cocoa-related memory management issues in the Memory Management Programming Guide for Cocoa (http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html). Because `indexPathWithIndexes:length` doesn't have 'new', 'copy', or 'alloc' in the selector, the Cocoa rules specify that it returns an autoreleased instance.
Barry Wark
+13  A: 

You can also use from the /NSIndexPath UIKit Additions/ (UITableView.h)

  • +(NSIndexPath *)indexPathForRow:(NSUInteger)row inSection:(NSUInteger)section
Aha! Documentation (of sorts) for the "undocumented API" about which I asked in another Q. Thanks! :)
Olie
it's very well documented: http://developer.apple.com/iphone/library/documentation/uikit/reference/NSIndexPath_UIKitAdditions/Reference/Reference.html, however it is only available on the iphone (UIKit).
Ben