Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将节和行indexpath分配给prepareForSeague_Ios_Uitableview - Fatal编程技术网

Ios 将节和行indexpath分配给prepareForSeague

Ios 将节和行indexpath分配给prepareForSeague,ios,uitableview,Ios,Uitableview,我正在尝试为我的prepareForSeague获取indexpath.section和indexpath.row。我可以传递indexpath.row没有问题,但是我正在努力将其与节集成。它在第一节之外传递正确的数据,但不在第一节之外传递,因为我不知道如何设置节 所以基本上我也需要知道它在哪个部分 我查看了对象索引 NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; dynamicDetailTableViewC

我正在尝试为我的
prepareForSeague
获取
indexpath.section
indexpath.row
。我可以传递
indexpath.row
没有问题,但是我正在努力将其与节集成。它在第一节之外传递正确的数据,但不在第一节之外传递,因为我不知道如何设置节

所以基本上我也需要知道它在哪个部分

我查看了
对象索引

NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
dynamicDetailTableViewController *destViewController = segue.destinationViewController;
NSLog(@" indexPath row %d",indexPath.row);
NSLog(@" indexPath section %d",indexPath.section);

// Assume self.view is the table view
destViewController.titleString = [self.namesArray objectAtIndex: indexPath.row];
//Health
destViewController.healthArray = [self.healthArray objectAtIndex:indexPath.row];
编辑


更清楚地说,它确实有效,但是我有不同的部分,所以在第一部分之后,它没有传递正确的值。它只传递正确的前几节值,因为它只基于行而不是节计算indexpath。我也需要它来计算节,但不确定如何计算。

如果有多个节和行,我猜您的数据结构是错误的。您的数据结构应该如下所示

第1节

---->第1行

---->第2排

---->第3排

第2节

---->第1行

---->第2排

第3节

---->第1行

---->第2排

---->第3排

---->第4排

要获取这些值,您的代码应该是

[[self.array objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
上面的代码表示,对于特定的
部分
,给我特定的

在您的例子中,情况似乎并非如此,您已经在单个数组中获得了所有数据,其中应该是数组的数组

您得到的值是错误的,因为对于每个indexPath.section,您的indexPath.row都以0开头,所以对于第一节,它可以正常工作,但对于其他节则不行


希望有帮助。

看起来不错,
NSLog
不是输出了预期值吗?或者有什么问题吗?打印行和节时,您在日志中看到了什么?抱歉,可能我不清楚。无论我有什么不同的部分,它都会工作,所以在第一部分之后,它不会传递正确的值。