ios – 比较NSIndexPath

前端之家收集整理的这篇文章主要介绍了ios – 比较NSIndexPath前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这将是一个非常愚蠢的东西,但我的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,因此您需要在进行比较之前确保它不为零.
if (self.indexPathSelected && [self.indexPathSelected compare:indexPath] == NSOrderedSame)
{
    NSLog(@" %d %d %d %d",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.

原文链接:https://www.f2er.com/iOS/336620.html

猜你在找的iOS相关文章