首页 文章

如何在tableview中选择一个按钮? [重复]

提问于
浏览
-2

这个问题在这里已有答案:

我可以使用swift 3的tableview中的“didSelectRowAt”函数选择行 . 但是当我连续选择一个按钮时,如何执行其他操作?我不知道如何在tableview中选择一个按钮 .

image

2 回答

  • 0

    创建一个出口操作:使用此代码查找索引路径

    @IBAction func memberPicTapped(_ sender:UIButton) {
                var superView = sender.superview
                while !(superView is UITableViewCell) {
                    superView = superView?.superview
                }
                let cell = superView as! UITableViewCell
                if let indexpath = YourTableView.indexPath(for: cell){
    
                }
          }
    
  • 0

    创建自定义单元格
    在UItableview方法的 cellForRowAt indexPath 中写下面的代码

    cell.buttonname?.addTarget(self, action: #selector(self.buttonmethod), for: .touchUpInside)
    cell.buttonname.tag = indexPath.section
    

    //按钮单击方法

    func buttonmethod(_ button: UIButton) {
         print(button.tag)
         // perform some action
    }
    

相关问题