如何替换(n?)UIButton的现有操作? [英] How do I replace the existing action of a(n?) UIButton?
本文介绍了如何替换(n?)UIButton的现有操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
到目前为止,我一直在使用
So far, I've been using
[button1 addTarget:self action:@selector(newAction) forControlEvents:UIControlEventTouchUpInside];
增加了额外的动作(我认为)。如何用新的操作替换初始操作?
which adds an additional action (I think). How can I replace the initial action with a new one?
推荐答案
您可以删除特定操作的目标,如下所示:
You can remove a target for a specific action like this:
[button1 removeTarget: self action: @selector(oldAction) forControlEvents: UIControlEventTouchUpInside]
或者,更好的是,您可以删除按钮中的所有目标,如下所示:
Or, better yet, you can remove all targets from your button like this:
[button1 removeTarget: nil action: NULL forControlEvents: UIControlEventAllEvents]
然后,您可以添加新的目标操作:
Then, you can add your new target action:
[button1 addTarget:self action:@selector(newAction) forControlEvents: UIControlEventTouchUpInside];
这就是它!
希望这很有帮助,
Pawel
Hope this was helpful, Pawel
这篇关于如何替换(n?)UIButton的现有操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文