NSIndexPath递增值 [英] NSIndexPath incrementing values

查看:114
本文介绍了NSIndexPath递增值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个XML文件的内容填充一个OutlineView。



我想创建和管理NSIndexPath中的值,文件。
NSIndexPath有添加和删除索引的方法,但我需要递增/递减每个索引中的值:



[0,0]
[0,1]

[0,2]



等等...


解决方案

NSIndexPath不可变,所以你必须每次都创建一个新的索引路径。可能最有效的方法是使用 length getIndexes: initWithIndexes:length :消息,以及用于增加/减小缓冲区的 realloc 函数。



Don在获取其索引到缓冲区之后 alloc king和<$ c之前,不要忘记释放 $ c> init ing( WithIndexes:length:)新的 >完成后的缓冲区。 (也不要忘记, realloc 为你释放了旧的缓冲区,所以你只需要 free 最后一个缓冲区。)


I am trying to populate an OutlineView with the contents of a XML file.

I'd like to create and manage the values inside a NSIndexPath while cocoa parses the document. NSIndexPath has methods to add and remove indexes, but I need to increment/decrement the values in each index:

[0, 0]
[0, 1]
[0, 2]

and so on...

how can I do that?

解决方案

NSIndexPath isn't mutable, so you'll have to create a new index path every time. Probably the most efficient way would be to use length, getIndexes:, and initWithIndexes:length: messages, plus the realloc function to grow/shrink the buffer.

Don't forget to release the old index path after getting its indexes into the buffer and before allocking and initing (WithIndexes:length:) the new one, and to free the buffer when you're done. (Also don't forget that realloc frees the old buffer for you, so you only need to free the last buffer.)

这篇关于NSIndexPath递增值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆