我在自定义 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/