代码拾遗录——轻松获取细胞里的按钮的indexPath

,——(instancetype) initWithStyle: (UITableViewCellStyle)风格reuseIdentifier: (NSString *) reuseIdentifier: (UITableView *)表
{
,,,自我=[超级initWithStyle:风格reuseIdentifier: reuseIdentifier];
,,,如果(自我){
,,,,,,,自我。tableView=表;
,,,,,,,(自我createUI);
,,,}
,,,回归自我;
}

- (void) createUI
{
,,,自我。写成backgroundColor=[用户界面颜色purpleColor];
,,,self.textLabel。字体=[UIFont systemFontOfSize: 50.0 f];
,,,,
,,,UIButton *按钮=[UIButton buttonWithType: UIButtonTypeCustom];
,,,button.frame=(CGRect中){0,0,60岁,40};
,,,按钮。写成backgroundColor=[用户界面颜色whiteColor];
,,,【按钮addTarget:自我行动:@ selector (clickAction:事件:)forControlEvents: UIControlEventTouchUpInside],
,,,自我。accessoryView=按钮;
}

- (void) clickAction: sender  (UIButton *);事件:事件(id)
{
,,,NSSet *触摸=[事件allTouches];
,,,UITouch *联系=[触动anyObject];
,,,CGPoint currentTouchPosition=[locationInView触:self.tableView];
,,,,
,,,NSIndexPath * indexPath=[自我。tableView indexPathForRowAtPoint: currentTouchPosition],
,,,如果(indexPath !=nil) {
,,,,,,,NSLog (@ % @”, indexPath);
,,,}
}

关键代码要将表传入细胞里面还有一句,,indexPathForRowAtPoint:


代码拾遗录——轻松获取细胞里的按钮的indexPath