UITableViewCell子视图的NSIndexPath? [英] NSIndexPath of UITableViewCell subview?

查看:94
本文介绍了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];
}

这篇关于UITableViewCell子视图的NSIndexPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆