2017-02-21 26 views
-2

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

image

+0

看到这个http://stackoverflow.com/questions/31649220/detect-button-click-in-table-view-ios-xcode-for-multiple-row-and-section/31649321#31649321 –

+0

你想按钮的多选或单选。 –

+0

我将使用多个选择按钮。 – Travis

回答

0

创建一个出口动作:并找到indexpath使用该代码

@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

非常感谢!它的工作! – Travis

+0

没问题Travis – Anuraj

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 
} 
+0

这是Swift 3的版本代码吗?在我的情况下,它不起作用。 – Travis

相关问题