iOS获取特定的UITableViewCell [英] iOS get specific UITableViewCell

查看:48
本文介绍了iOS获取特定的UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自定义 UITableViewCell 中有 UIButton 。单击此按钮会触发事件。

I have a UIButton in a custom UITableViewCell. This button triggers an event when clicked.

[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 

单击按钮时调用的方法是:

The method which is called when the button is clicked is :

 - (void) buttonClicked:(id)sender
{

UIButton *b = (UIButton*)sender;

.....

} 

我的问题是,如何获得按钮所在单元格的实例?

My question is, how can I get an instance of the cell in which the button is placed?

推荐答案

 UITableViewCell *cell = (UITableViewCell*)[[b superview] superview];

如果您将单元格上的按钮添加为子视图,则按钮的superview将是contentView,contentView的superview将UITableViewCell

If you added the button on cell as subview then superview of button will be contentView and superview of contentView will UITableViewCell

这篇关于iOS获取特定的UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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