UITableView,我如何知道cellForRowAtIndexPath期间的哪个部分? [英] UITableView, how do I know what Section during cellForRowAtIndexPath?
问题描述
我有一个显示城市列表的UITableView。
我想把它们按国家分开。我似乎无法弄清楚如何从我的阵列中选择正确的项目。
如果第1节(亚利桑那州)有2个城市而第2节(加利福尼亚州)有2个城市,则在cellForRowAtIndexPath第2节中,城市1的索引为0,即使它是我的数组中的第3个项目。
我想把我的城市阵列变成一个状态数组,其中每个项目都有一个城市阵列,但我仍然不知道我在哪个部分,因此不知道哪个城市阵列在我需要访问的数组。
I have a UITableView displaying a list of Cities. I want to separate them by State. I can't seem to figure out how to get it to pick the right items out of my Array. If Section 1 (Arizona) has 2 Cities and Section 2 (California) has 2 Cities, during cellForRowAtIndexPath, Section 2, City 1 has an index of 0, even though it's the 3rd item in my array. I thought about just turning my City Array into a State Array, where each item holds an Array of Cities, but I still don't know what section I'm on and therefore don't know which City Array under the States Array I would need to access.
任何帮助都将不胜感激。
Any help would be appreciated.
推荐答案
该方法被称为
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
indexpath参数包含行和节属性。
The indexpath parameter contains a row and section property.
indexPath.section
indexPath.row
以下是
- 的文档链接 NSIndexPath class
- section,row和item properties adde d通过 NSIndexPath UIKit Additions 。
- The NSIndexPath class
- The section, row, and item properties added by NSIndexPath UIKit Additions.
这篇关于UITableView,我如何知道cellForRowAtIndexPath期间的哪个部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!