美文网首页
storyboard 中 cell上按钮 处理

storyboard 中 cell上按钮 处理

作者: Heikki_ | 来源:发表于2017-12-08 18:39 被阅读32次
    - (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上按钮 处理

          本文链接:https://www.haomeiwen.com/subject/bchyixtx.html