Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法以编程方式更改 UIButton 的 IBAction?
我知道我可以只创建两个按钮并使用 button.hidden = BOOL,但我宁愿只更改 IBAction 本身。
当然。您可以使用addTarget:forControlEvents:和removeTarget:action:forControlEvents:手动管理操作方法和控件之间的连接。两种方法都在UIControl.
addTarget:forControlEvents:
removeTarget:action:forControlEvents:
UIControl
我不确定我是否理解这个问题?为什么不让 IBAction 调用自定义方法并在该方法中添加一些关于要采取哪些操作的逻辑?
当然:
-removeTarget:action:forControlEvents:删除旧动作
-addTarget:action:forControlEvents:添加新动作