gpt4 book ai didi

ios - 在 Swift 4 中对 UIButton 添加操作

转载 作者:行者123 更新时间:2023-11-28 09:24:35 28 4
gpt4 key购买 nike

<分区>

当我将 Swift 3 应用程序迁移到 4 Xcode 时,Xcode 要求我在我的几个函数前面添加 @objc。当我这样做时,它向我显示了“@objc 已被弃用”的警告我想知道是否有更好的解决方案来处理 Swift 4 中的 addTarget

enter image description here

这是我的 UIButton :

let playButton: UIButton = {
let btn = UIButton(type: .system)
btn.setTitle("Play", for: .normal)
btn.setTitleColor(.green, for: .normal)
btn.addTarget(self, action: #selector(playTapped), for: .touchUpInside)
return btn
}()

函数:

@objc func playTapped() {
let path = AudioPlayerManager.shared.audioFileInUserDocuments(name: "test")
AudioPlayerManager.shared.playAudio(path: path)
}

不使用 #selector 和 `@objc' 可以给按钮添加 Action 吗?

谢谢。

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