我有一个 subview ,它有一个选择器
let subView1: CustomSubView = CustomSubView(frame: CGRect(x: 0, y: 0 , width: xx, height: yy))
subView1.label.text = "Lorem Ipsum"
cell.scroller.addSubview(subView1)
let gesture = UITapGestureRecognizer(target: self, action: #selector(self.subView1Action(_:)))
subView1.addGestureRecognizer(gesture)
func subView1Action(sender:UITapGestureRecognizer){
print("Wow Subview1 is clicked")
}
现在,我想将标签文本发送到选择器函数。我该怎么做? 如果我使选择器功能如下:
func subView1Action(sender:UITapGestureRecognizer , label:String){
print(label)
}
我应该怎么调用它?
最佳答案
只需将 UITapGestureRecognizer
作为唯一的函数参数。然后您可以使用 sender.view as 访问标签? UILabel
.
关于ios - 如何将多个参数传递给选择器函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37020216/