ios - 如何将多个参数传递给选择器函数

标签 ios swift uigesturerecognizer selector

我有一个 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/

相关文章:

iphone - 是否可以在没有Windows或Linux且没有其中一种设备的情况下针对iPhone/iPod Touch进行开发?

ios - 如何告诉 iOS 设备停止记住/忘记特定应用程序的位置服务偏好

ios - 为什么已删除的文件在新写入文件后又会回来? swift 2.0

ios - 为什么我的 MKPointAnnotation 在 View 加载时没有出现?

xcode - 使用未解析的标识符 'FIRDatabase'

iphone - UIView 的一部分的 UIGestureRecognizer

Info.plist 中缺少 iOS 9 “fbauth2”

ios - 使用 Swift 从 Firebase 数据库创建过滤 TableView 的最佳方法是什么

ios - 使用长按时出现两个 Action 表

ios - 如何禁用 "gesture recognizer"(XMCircleGestureRecognizer)?