ios – 比较NSIndexPath

ios – 比较NSIndexPath,第1张

概述这将是一个非常愚蠢的东西,但我的cellForRowAtIndexPath中有这个代码: if ([self.indexPathSelected compare:indexPath] == NSOrderedSame){ NSLog(@" %d %d %d %d", self.indexPathSelected.row, self.indexPathSelected.section, i 这将是一个非常愚蠢的东西,但我的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.

总结

以上是内存溢出为你收集整理的ios – 比较NSIndexPath全部内容,希望文章能够帮你解决ios – 比较NSIndexPath所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1111776.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存