什么是 NSIndexPath

发布于 2024-11-09 09:45:45 字数 106 浏览 0 评论 0原文

NSIndexPath 的具体工作是什么, 我的理解是,IndexPath 变量用于引用我们要显示的单元格 ?:o ? 但它存储什么价值呢?我是说。, 设置indexPath变量的内部过程是什么

What exactly is the job of NSIndexPath,
What I understand is, IndexPath variable is used to refer the cell which we want to display ?:o ?
But what value does it store ? I mean.,
What is the internal process that happen to setup an indexPath variable

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

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

发布评论

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

评论(4

初心未许 2024-11-16 09:45:45

它用作在数组内引用数组的向量。例如,您可以使用 IndexPath 表示 array[a][b][c] 的路径。在内部,它用于 iPhone 列表视图,例如允许您选择一个国家/地区的列表视图,然后为您提供区域选项,然后是该区域中的城市列表。您选择的城市的索引路径将包括通过国家和地区到达该城市的路径。

特别是对于 UITableViews 来说,NSIndexPath 扮演着稍微更扩展的角色。 UIKit 将行和节属性添加到 NSIndexPath 的实例中,以及类方法 + indexPathForRow:inSection:。

因此,如果要选择或删除表中的特定行,则需要将 NSIndexPath 的实例传递给该表。要创建它,您可以使用 indexPathForRow:inSection 创建一个 NSIndexPath 实例。

如果您想要获取现有的 NSIndexPath 信息并且它来自表视图,则使用其行和节属性来获取数据。

如果您在表视图之外遇到索引路径,请注意其使用的细节。无论哪种方式,一般来说,它都是对数组数组中特定元素的引用。

It is used as a vector for referencing arrays within arrays. For example you can represent a path to array[a][b][c] using an IndexPath. Internally it is used for iPhone list views, for example a list view that allows you to select a country, then gives you an option of regions, followed by a list of cities in the said region. The indexpath to the city you selected would include the path to it through the country and region.

Specifically for UITableViews, NSIndexPath plays a slightly more expanded role. UIKit adds the row and section properties to an instance of NSIndexPath, and a class method + indexPathForRow:inSection:.

Therefore if you want to select or delete a specific row in a table, you would need to pass an instance of NSIndexPath to that table. To create that, you would use indexPathForRow:inSection to create an NSIndexPath instance.

If you have an existing NSIndexPath that you want to get info about and it's from a table view, then use its row and section properties to get the data.

If you encounter index paths outside of the table view, be careful regarding the specifics of its use. Either way, in general, it is a reference to a specific element in arrays of arrays.

能怎样 2024-11-16 09:45:45

在 iOS 中,NSIndexPath 对象的长度始终为 2。例如,它们用于索引表视图单元格。 NSIndexPath 对象中的第一个索引称为 section,第二个索引称为 row。具有第 0 部分和第 0 行的索引路径对象表示第一个部分中的第一行。
这就是在 iOS 上处理索引路径时您需要了解的全部内容。

In iOS the NSIndexPath objects are always of length 2. They're used for example to index a table view cell. The first index in a NSIndexPath object is called the section, the second is the row. An index path object with section 0 and row 0 indicates the first row in the first section.
Thats all you need to know when dealing with index paths on iOS.

比忠 2024-11-16 09:45:45

苹果的课程参考文档仅对那些将心智模型实例化到其认知过程中的人有用。当有人提出诸如原始帖子之类的问题时,即使他们无法完全清楚地表达出他们的困惑,类参考文档也是有史以来发布的最精彩的非信息之一。我也在努力弄清楚如何——用另一个答案的话——填写“//计算一些索引路径”(只知道单元格的整数偏移量......我想选择我的第n个item),并且正在寻找与原始帖子相同级别的概念概述,所以我想我应该解释一下这个困境。

Apple's class reference documentation is useful only for people who HAVE the mental model instantiated into their cognitive processes. When someone asks a question such as the original post, even if they are unable to fully articulate their confusion, the class reference documentation is some of the most wonderful non-information ever published. I too am struggling to figure out how---in the words of another SO answer---to fill in "// compute some index path" (knowing only an integer offset of the cell... I want to select my nth item), and am looking for the same level of conceptual overview as the original post, so I thought I'd explain the dilemma a bit.

埋情葬爱 2024-11-16 09:45:45

我不是 100% 确定你在问什么,但有更多信息 此处

I'm not 100% sure what you're asking, but there is more information here.

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