我有一个应用程序,在我升级到XCODE 5之前曾经工作过。我需要找到为我正在显示的结构选择的行,它有超过100行,所以显然可以在显示屏上滚动。以前的代码是:
NSIndexPath *indexPath = [self.mainTableView indexPathForCell:myCell];
NSInteger row = [indexPath row];
现在,无论选择哪一行,行的值始终为0.任何人对我有什么建议吗?感谢。
答案 0 :(得分:0)
这对我有用......
CGPoint pos = [pressedButton convertPoint:CGPointZero toView:self.mainTableView];
NSIndexPath * indexPath = [self.mainTableView indexPathForRowAtPoint:pos];
NSInteger row = [indexPath row];
答案 1 :(得分:0)
请记住,在Objective-C中,您始终可以发送消息nil
,并且返回某些内容的方法(即,不是void
)将返回nil
(对于对象)发送到0
时,或nil
(对于某个值)(对于结构,它更复杂; read this)。
所以请确保:
self.mainTableView
不 nil
indexPath
不 nil