gpt4 book ai didi

ios - 如何在 Swift 4 中以编程方式将 IBAction 添加到按钮?

转载 作者:搜寻专家 更新时间:2023-10-31 21:58:59 26 4
gpt4 key购买 nike

如何以编程方式将 IBAction 添加到按钮?

button.addTarget(self, action: Selector(("buttonAction:")), for: 
.touchUpInside)

func buttonAction(sender: Any) {
print("test")
}

这给了我一个“Thread 1: signal SIGABRT”错误。

最佳答案

swift 4 版本:

button.addTarget(self, action: #selector(action(sender:)), for: .touchUpInside)

@objc private func action(sender: Button) {
print("test")
}

关于ios - 如何在 Swift 4 中以编程方式将 IBAction 添加到按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46949969/

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