NSIndexPath getIndexes 方法...如何?

发布于 2024-10-21 21:03:51 字数 350 浏览 7 评论 0原文

我对该方法的使用以及将其列为(无效)方法的文档感到困惑。

“返回索引路径的索引”

它在哪里也返回任何内容?

不应该是:

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

getIndexes: 提供对索引路径索引的引用。

- (void)getIndexes:(NSUInteger *)indexes

参数 索引 指向无符号整数数组的指针。返回时,索引路径的索引。 可用性 适用于 iOS 2.0 及更高版本。 申报于 NSIndexPath.h

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

穿透光 2024-10-28 21:03:51

您必须分配大小为 [indexPath length] 的 NSUInteger 数组并将其作为参数传递。返回值将写在那里。您必须自己释放该数组,或者不执行在堆栈上创建的数组,如下所示:

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

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];
我不在是我 2024-10-28 21:03:51

也许下一句话就能解释原因

开发人员负责为 C 数组分配内存。

它实际上是一个指向 C 数组的指针,该数组将为您填充索引,因此没有理由另外从函数中返回它 - 您已经知道它的地址。

您可以按如下方式使用该功能

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

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];
遮云壑 2024-10-28 21:03:51

您将该消息发送到 NSIndexPath 的一个实例,因此返回该消息并没有帮助。 -getIndexes: 方法用索引路径中的索引填充数组“indexes”。因此,您可以执行以下操作:

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

之后,索引将填充indexPath 中的索引值。

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.

无力看清 2024-10-28 21:03:51

马克斯、托马斯和迦勒,我已经尝试了所有三种方法,但无法让任何东西发挥作用,所以也许太快地推出了接受的解决方案......但可能更有可能我只是不明白?我无法获得正确的数组大小,以便循环遍历它以访问表中所需的行。我认为对于 5 行的组,calloc([indexPath length], sizeof(NSUInteger)) 会返回一个包含 5 行的数组,每行保存 NSUIntegr。 ....或者我离得太远很尴尬吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文