更新时间:2023-01-06 10:59:04
还需要一个 superView
致电:
OTATableCell *cell = (OTATableCell *)[[[button superview] superview] superview];
您可以查看以下内容:
对于iOS> = 7:
For iOS >= 7:
NSLog(@"%@",[[sender superview] class]); //UITableViewCellContentView
NSLog(@"%@",[[[sender superview] superview] class]); //UITableViewCellScrollView
NSLog(@"%@",[[[[sender superview]superview]superview] class]); //UITableViewCell
适用于iOS< 7:
For iOS < 7:
NSLog(@"%@",[[sender superview] class]); //UITableViewCellContentView
NSLog(@"%@",[[[sender superview] superview] class]); //UITableViewCell
NSLog(@"%@",[[[[sender superview]superview]superview] class]); //UITableView
编辑:如果你不想依赖 superView
属性:
UIButton *button = (UIButton *)sender;
CGRect buttonFrame = [button convertRect:button.bounds toView:self.table];
NSIndexPath *indexPath = [self.table indexPathForRowAtPoint:buttonFrame.origin];
//使用 indexPath
访问单元格:
//Access the cell using indexPath
:
UITableViewCell *cell=[self.table cellForRowAtIndexPath:indexPath];
cell.label=@"setText";