这将是一个非常愚蠢的东西,但我的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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。