iOS 获取特定的 UITableViewCell

标签 ios uitableview

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

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

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

 - (void) buttonClicked:(id)sender
{

UIButton *b = (UIButton*)sender;

.....

} 

我的问题是,如何获取放置按钮的单元格的实例?

最佳答案

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

如果您在单元格上添加按钮作为 subview ,那么按钮的父 View 将是 contentView,而 contentView 的父 View 将是 UITableViewCell

关于iOS 获取特定的 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13509216/

相关文章:

ios - 导航组中的自定义后退按钮(Titanium Mobile)

ios - Swift:在 UITableViewCell 中异步加载图像 - 自动布局问题

ios - iOS 中tableview 的分页问题

iphone - UITableView 没有从 NSUserDefaults 中删除记录

ios - 在 uiscrollview 中检测 toucesbegin

ios - 打开 GL ES 1 和 iOS 5 引用

ios - 为什么我的 tableView 变量返回 nil?

ios - 数据未在详细 View 中加载

iOS PWA "Add to Home Screen"- 禁用全屏模式

javascript - 使用蓝牙键盘时隐藏移动 Safari 键盘。