UITableViewCell子视图的NSIndexPath?
有没有获取UITableViewCell的contentView子视图的NSIndexPath?
Is there any was to get the NSIndexPath of a UITableViewCell's contentView subview?
在我的情况下,我有一个表视图,其中每行被分成3个按钮。我可以使用按钮标记来跟踪它是哪一列,但我还需要知道表视图的哪一行是(当用户点击按钮时)的子视图。
In my case, I have a table view in which each row is split into 3 buttons. I can use the button tag to keep track of which column it is but I also need to know what row of the table view it is a subview of (when the user taps the button).
因为按钮会阻塞整个实际的表视图行,所以从不调用didSelectRowAtIndexPath(这是预期的),所以我无法这样做。
Because the button blocks the entire actual table view row, didSelectRowAtIndexPath is never called (which is expected), so I can't get it that way.
我尝试过[thisButton superview],但这似乎不起作用。有什么想法吗?
I have tried just [thisButton superview] but that doesn't seem to work. Any thoughts?
我认为该按钮正在发送其 UIControlEventTouchUpInside
事件消息给您的视图控制器?然后你可以这样做:
I assume the button is sending its UIControlEventTouchUpInside
event message to your view controller? Then you could do something like:
- (void)buttonPressed:(UIButton *)button
{
CGPoint location = [button.superview convertPoint:button.center toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
[self doSomethingWithRowAtIndexPath:indexPath];
}