我有一个 UIButton。我绑定(bind)了一个目标如下。
[button addTarget:self action:@selector(myFunction)
forControlEvents:UIControlEventTouchUpInside];
当我快速多次单击我的按钮时,它会多次调用目标函数。 在点击按钮上,我展示了一个新的 View Controller 。 当我快速单击 3 次时,我的新 View Controller 将显示 3 次。
这是愚蠢的事情。一旦 View 已转移到新的 View Controller ,再次触发该功能有什么意义。为什么 hell 苹果会做出如此愚蠢的事情?
有什么帮助吗?
最佳答案
首先,它不是 apple bug。应该手动处理。所以按照这些步骤
首先创建按钮的全局实例,然后执行此操作
.h文件
@property (weak, nonatomic) IBOutlet UIButton *btn;
.m文件
- (IBAction)myFunction:(id)sender
{
self.btn.userInteractionEnabled = NO;
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.btn.userInteractionEnabled = YES;
}
关于ios - 多次点击 UIButton 多次触发 Target 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30972471/