gpt4 book ai didi

ios - 滚动 UITableviewcells 时 IndexPath 值正在改变?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:23 25 4
gpt4 key购买 nike

first view controller 移动到 second view controller 时,我将索引路径保存在数组中,并在 first view controller 中加载表时返回,如果当前索引路径在保存的索引路径数组中,我必须创建一个自定义附件按钮。

但是,当滚动 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;
}

最佳答案

我不记得文档中有任何部分说索引路径是要被 TableView 重用的,然后将对象与 designed function 进行比较可能是个好主意。 :

compare:

Indicates the depth-first traversal order of the receiving index path and another index path.

-(NSComparisonResult)compare:(NSIndexPath *)indexPath

Parameters

indexPath Index path to compare. This value must not be nil. If the value is nil, the behavior is undefined.

Return Value

The depth-first traversal ordering of the receiving index path and indexPath.

  • NSOrderedAscending: The receiving index path comes before indexPath.
  • NSOrderedDescending: The receiving index path comes after indexPath.
  • NSOrderedSame: The receiving index path and indexPath are the same index path.

Availability

Available in iOS 2.0 and later.

Declared In

NSIndexPath.h

关于ios - 滚动 UITableviewcells 时 IndexPath 值正在改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14378363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com