以编程方式快速添加按钮

问题描述 投票:0回答:2

[我试图以编程方式添加按钮,我创建了按钮,它在应用程序中显示,但是问题是当我在.addTarget中写入#selector时发生错误(成功构建,但操作不起作用),我尝试编写[ C0],playAction()playAction(sender:)。他们都不工作。 playAction

enter image description here
swift uibutton addtarget
2个回答
0
投票

您的函数需要具有playPauseButton.addTarget(self, action: #selector(playAction(sender:)), for: .touchUpInside) @objc func playAction(sender: UIButton){ print("Hello") } 属性。这使它可以作为选择器查找。


0
投票

更改方式

© www.soinside.com 2019 - 2024. All rights reserved.