【发布时间】:2013-06-24 15:22:37
【问题描述】:
这将是一件非常愚蠢的事情,但我的 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 ? -
是的。将其更改为 self.indexPathSelected = [NSIndexPath indexPathForRow:-1 inSection:-1];修复。两个后续问题,为什么'nil'不起作用?第二个是将其设置为 -1、-1 是否正确?
-
向 nil 发送消息将始终导致 nil => 0。只需检查您是否在与 nil 进行比较。
标签: ios uitableview nsindexpath