开发者

NSIndexPath getIndexes method....how?

Am开发者_开发百科 confused with the use of this method and the documentation that lists it as a (void) method.

"on return the index path's indexes"

where does it return anything too?

Should it not be:

- (NSIndexPath *)getIndexes:(NSUInteger *)indexes

getIndexes: Provides a reference to the index path’s indexes.

- (void)getIndexes:(NSUInteger *)indexes

Parameters indexes Pointer to an unsigned integer array. On return, the index path’s indexes. Availability Available in iOS 2.0 and later. Declared In NSIndexPath.h


You have to allocate the NSUInteger array of size [indexPath length] and pass it as argument. The return value will be written there. You have to release that array yourself or do nothing it was created on stack like this:

NSUInteger array[[indexPath length]];
[indexPath getIndexes: array];


Maybe the next sentence explains the reason

It is the developer’s responsibility to allocate the memory for the C array.

It's actually a pointer to a C array that will be filled for you with the indexes, so there's no reason to additionally return it from the function - you already know its address.

You can use the function as follows

NSUInteger indexCount = [indices count];
NSUInteger buffer[indexCount];
[indices getIndexes:buffer maxCount:indexCount inIndexRange:nil];


You send that message to an instance of NSIndexPath, so getting one back wouldn't help. The -getIndexes: method fills the array 'indexes' with the indexes from the index path. So you'd do something like:

NSUInteger *indexes = calloc([indexPath length], sizeof(NSUInteger));
[indexPath getIndexes:indexes];

After that, indexes will be filled with the index values that are in indexPath.


Max, Thomas and Caleb, I have tried all three ways and cannot get anything to work, so maybe fired off the accepted solution too quick.....but probably more likely I just don't get it? I can't get the right size of the array in order to loop through it to access the required rows in my table. I would have though that calloc([indexPath length], sizeof(NSUInteger)) would for a group with 5 rows return an array with 5 rows with each row holding NSUIntegr.....or am of so far off beam it embarrassing?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜