gpt4 book ai didi

ios - 带有两个参数的快速选择器未触发

转载 作者:行者123 更新时间:2023-11-28 08:31:12 25 4
gpt4 key购买 nike

我正在尝试使用带有两个参数的选择器

我为此使用了这段代码

func yourButtonClicked(sender : AnyObject, rcd :  NSManagedObject)
{ }

我必须传递参数record1

cell.btn.addTarget(self, action: #selector(yourButtonClicked(_:record1)), forControlEvents: UIControlEvents.TouchUpInside)

它显示错误 missing arg rcd in call

有人能纠正我吗?

最佳答案

当您在 addTarget 方法中设置选择器时,您只是在告诉您的对象它应该在“target”对象中搜索具有给定参数名称签名的“action”方法,并在事件发生时调用它。您无法提供应在调用中用作参数的属性或变量。如果你会阅读docUIControl 为例,您会发现 addTarget 方法只允许对您的操作进行三个签名。

要解决您的问题,您可以声明属性并在您的操作中使用它:

var rcd: NSManagedObject!
func yourButtonClicked(sender : AnyObject) {
//use rcd property, keeping it in actual state
}

func someMethod() {
rcd = record1
cell.btn.addTarget(self, action: #selector(yourButtonClicked(_:)), forControlEvents: .TouchUpInside)
}

关于ios - 带有两个参数的快速选择器未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38845394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com