【发布时间】:2011-11-15 23:31:55
【问题描述】:
我一直在寻找解决方案,但似乎找不到适合我的解决方案。我有一个自定义单元格,里面有一个按钮。我的问题是如何将 indexPath 传递给 action 方法?
我现在正在做
[cell.showRewards addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventTouchUpInside];
在我的 cellForRowAtIndexPath 方法中,我的方法是:
-(IBAction)myAction:(id)sender{
NSIndexPath *indexPath = [self.tableView indexPathForCell:(MyCustomCell *)[sender superview]];
NSLog(@"Selected row is: %d",indexPath.row);
}
有什么建议吗?谢谢。
【问题讨论】:
-
你在使用 didSelectRow: 方法吗?
标签: iphone objective-c ios uitableview uibutton