gpt4 book ai didi

ios - 比较 NSIndexPath

转载 作者:技术小花猫 更新时间:2023-10-29 10:30:16 27 4
gpt4 key购买 nike

这将是一件非常愚蠢的事情,但我的 cellForRowAtIndexPath 中有这段代码:

if ([self.indexPathSelected compare:indexPath] == NSOrderedSame)
{
NSLog(@" %d %d %d %d", self.indexPathSelected.row, self.indexPathSelected.section, indexPath.row, indexPath.section);
}

这打印:

0 0 0 0

0 0 1 0

0 0 2 0

0 0 3 0

0 0 4 0

0 0 5 0

我原以为它只会打印 0 0 0 0。

我在这里做错了什么?

最佳答案

由于您将 indexPathSelected 设置为 nil,因此您需要在进行比较之前确保它不为 nil。

if (self.indexPathSelected && [self.indexPathSelected compare:indexPath] == NSOrderedSame)
{
NSLog(@" %d %d %d %d", self.indexPathSelected.row, self.indexPathSelected.section, indexPath.row, indexPath.section);
}

根据 NSIndexPath's compare method 上的文档:

Parameters

indexPath

Index path to compare.

This value must not be nil. If the value is nil, the behavior is undefined.

关于ios - 比较 NSIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17279131/

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