Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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 目标C-不正确的细胞数据_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 目标C-不正确的细胞数据

Ios 目标C-不正确的细胞数据,ios,objective-c,uitableview,Ios,Objective C,Uitableview,切入话题。 我定义了一个数组,变量I声明如下 @interface KTCBLocationTableViewController () { NSArray *deserializedArray; int i; } 它存储从远程数据库检索的数据,当我使用以下代码查看其中的内容时,该数据库最终包含以下数据 //This line is inside a for-loop [[deserializedArray objectAtIndex:i] objectForKey:@"rna

切入话题。 我定义了一个数组,变量I声明如下

 @interface KTCBLocationTableViewController () {
   NSArray *deserializedArray;
   int i;
 }
它存储从远程数据库检索的数据,当我使用以下代码查看其中的内容时,该数据库最终包含以下数据

//This line is inside a for-loop
[[deserializedArray objectAtIndex:i] objectForKey:@"rname"];
上述代码的结果显示以下数据

Location A Location B Location C Location D Location E Location F Location G Location H 我发现细胞在皱褶后会发生变化,位置A可能会变成G或其他位置

我看了看队伍

cell.textLabel.text = [[deserializedArray objectAtIndex:i] objectForKey:@"rname"]; // only top row showing
i++;

我认为这就是问题所在。但是,我不知道如何将数组中的所有数据“填充”到每行的单元格中并使其一致。

使用“indexPath.row”。改变

cell.textLabel.text = [[deserializedArray objectAtIndex:i] objectForKey:@"rname"]; // only top row showing


你的问题很简单,但解决方法可能有点复杂。CellForRowatineXpath方法未按indexPath的顺序调用。我建议使用indexPath.row而不是I,尽管使用I并不容易。使用indexPath.row。每当您在UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier]中重新加载数据时,i++将增加@SunnyShah indexath.row在可折叠的tableview中不起作用,它将始终保持在0,使用indexath.section将产生与我上面所述的代码相同的结果我是什么?它没有在任何地方声明。如果它是一个实例变量,则该值会有点扭曲。@JUnitorProgrammer:cellForRowAtIndexPath将以任何顺序为可见单元格调用,并在滚动时重复调用。必须根据给定的索引XPath计算单元格内容。递增一个实例变量并依赖于按特定顺序调用的方法永远不会起作用。对不起,但我想我提到了在这个可折叠的tableview(注释中)中使用indexPath.row的问题。尽管如此,我还是尝试了你的解决方案,所有的数据都显示了位置A。你介意看看问题区域的评论吗?是的,我读过。就像马丁R暗示的,你必须摆脱我。我以前使用过可折叠节,我知道它们可以通过indexPath.section和indexPath.row完成
cell.textLabel.text = [[deserializedArray objectAtIndex:i] objectForKey:@"rname"]; // only top row showing
cell.textLabel.text = [deserializedArray[indexPath.row] objectForKey:@"rname"]; // only top row showing