UITableView的,我怎么知道的cellForRowAtIndexPath在什么科?
-
16-09-2019 - |
题
我有一个UITableView显示城市的列表。 我想国家把它们分开。我似乎无法弄清楚如何得到它挑选合适的项目我的阵列。 如果第1(亚利桑那州)有2个城市和第2节(加利福尼亚州)有2个城市,期间的cellForRowAtIndexPath,第2节,市1具有索引为0,即使它在我的数组的第三个项目。 我想到只是把我的城市阵列成状态数组,每个项目拥有城市的数组,但我仍然不知道我是什么节上,因此不知道哪个城市阵下的国阵我会需要的访问。
解决方案
的方法被称为
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
在indexpath参数包含一个行和区段属性。
indexPath.section
indexPath.row
下面的文档链接的 NSIndexPath 类。
其他提示
可以使用indexPath.section
和indexPath.row
夫特3,4和4.2
使用开关
switch indexPath.section {
case 0:
print("Write your code for section number one.")
case 1:
print("Write you code for section number two")
default:
return
}
使用的if else
if indexPath.section == 0 {
print("Write your code for section number one.")
} else if indexPath.section == 1 {
print("Write your code for section number two.")
}
不隶属于 StackOverflow