storyboard 中 cell上按钮 处理

- (IBAction)callToCounselor:(UIButton *)sender {
    HYTodayBookListCell *cell;
    UIView *superView = sender.superview;
    BOOL next = YES;
    do{
        if([superView isKindOfClass:[HYTodayBookListCell class]]){
            cell = (HYTodayBookListCell * )superView;
            next = NO;
        }else{
            superView = superView.superview;
            next = YES;
        }
    } while (next);
    
    NSIndexPath *path = [self.tableView indexPathForCell:cell];
    NSLog(@"%ld",path.row);
}

swift

    @IBAction func getCoinButtonDidClick(_ sender: UIButton) {
        
        var cell: ZKGetCoinCell?
        var superView = sender.superview
        
        var next = true
        repeat {
            if superView is ZKGetCoinCell{
                cell = superView as? ZKGetCoinCell
                next = false
            }else{
                superView = superView?.superview
                next = true
            }
        } while next
        
        guard cell != nil else {
            return
        }
        
        let indexPath = tableView.indexPath(for: cell!)
        dPrint(indexPath)
    }

你可能感兴趣的:(storyboard 中 cell上按钮 处理)