Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.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/0/iphone/41.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 滚动UITableviewcells时IndexPath值正在更改?_Ios_Iphone_Uitableview - Fatal编程技术网

Ios 滚动UITableviewcells时IndexPath值正在更改?

Ios 滚动UITableviewcells时IndexPath值正在更改?,ios,iphone,uitableview,Ios,Iphone,Uitableview,从第一视图控制器移动到第二视图控制器时,我将索引路径保存在数组中,并在第一视图控制器中加载表时返回,如果当前索引路径在保存的索引路径数组中,我必须创建一个自定义附件按钮 但是,当滚动UITableview以及所需单元格时,另一个单元格也会获得自定义按钮。当我在滚动时打印NSindexPaths时,我得到的是随机值,而不是正常值 对于以上内容,我使用以下代码: - (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAt

第一视图控制器
移动到
第二视图控制器
时,我将索引路径保存在数组中,并在
第一视图控制器
中加载表时返回,如果当前索引路径在保存的索引路径数组中,我必须创建一个自定义附件按钮

但是,当滚动
UITableview
以及所需单元格时,另一个单元格也会获得自定义按钮。当我在滚动时打印
NSindexPaths
时,我得到的是随机值,而不是正常值

对于以上内容,我使用以下代码:

- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
   // NSLog(@"newdata value is =%d",newData);
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    UITableViewCell *cell = [self.positionsTable dequeueReusableCellWithIdentifier:@"playersInPosition"];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"playersInPosition"]autorelease];
    }
    UILabel *lblName = (UILabel *)[cell viewWithTag:100];
    [lblName setText:[inputData objectAtIndex:[indexPath row]]];
    UILabel *pname = (UILabel *)[cell viewWithTag:102];
    [pname setText:[appDelegate.playersNFL objectAtIndex:[indexPath row]]];

      for (NSIndexPath *object in appDelegate.indexPathList) {
    if ([object isEqual:indexPath]) {
        NSLog(@"saved index path values are =%@",appDelegate.savedIndexPath);
        UIButton *button = [self ChangeAccessoryButtonStyle:appDelegate.indexPathList[0]];
        cell.accessoryView = button;
    }
    }
        return cell;
}

我不记得文档中有任何部分说过索引路径要被表视图重用,那么将对象与

比较:

指示接收的深度优先遍历顺序 索引路径和另一个索引路径

-(NSComparisonResult)比较:(NSIndexPath*)indexPath

参数

要比较的索引路径。此值不能为零。如果 值为零,行为未定义

返回值

深度优先 接收索引路径和indexPath的遍历顺序

  • SensorDeredAscending:接收索引路径位于indexPath之前
  • Underedescending:接收索引路径位于indexPath之后
  • SensorDeredName:接收索引路径和indexPath相同 索引路径
可用性

在iOS 2.0及更高版本中提供

声明于

nsindepath.h


每次尝试删除此行并创建单元格

UITableViewCell *cell = [self.positionsTable dequeueReusableCellWithIdentifier:@"playersInPosition"];

使用
NSString*CellIdentifier=[nsstringstringwithformat:@“%d”,indexPath.row]索引单元格在哪里保存索引路径?你能再解释一下你想实现什么吗?另外,由于单元重用,当
isEqual
如果
的计算结果为false时,您应该有一个else分支,其
cell.accessoryView=nil
。Hi@Templar我已将indexPath保存在-(void)tableView:(UITableView*)tableView accessorybuttonattappedforrowwithindexath:(nsindexath*)indexath{}中,因为,我在first view controller中有AccessoryDetailDisclosure按钮…感谢replyHi@A-Live感谢回复…所有代码都工作正常。但是,uitableview中单元格的indexpath值在滚动时正在更改。。我只是想知道在CellForRowatineXpath中声明单元格内容时是否有任何错误。。。