Iphone 双击按钮并回调至segue会导致崩溃
我有一个按钮:Iphone 双击按钮并回调至segue会导致崩溃,iphone,objective-c,callback,uibutton,segue,Iphone,Objective C,Callback,Uibutton,Segue,我有一个按钮: - (IBAction)themeBtnAction:(id)sender { NSString *language = [[OnlineStore sharedStore]getTheLanguage]; [[OnlineStore sharedStore]getTheThemeBaseGuides:language callback:^{ [self performSegueWithIdentifier:@"from main to t
- (IBAction)themeBtnAction:(id)sender
{
NSString *language = [[OnlineStore sharedStore]getTheLanguage];
[[OnlineStore sharedStore]getTheThemeBaseGuides:language callback:^{
[self performSegueWithIdentifier:@"from main to themecategory" sender:self];
}]
}
但当用户碰巧双击按钮时,会导致崩溃。可能是因为下一个viewcontroller将两次加载到堆中(我猜),当我尝试从第二个UIViewController
弹出返回时,收到的错误消息是:开始/结束外观转换的不平衡调用。
我该如何防止这种情况
我已尝试将其放在以下范围内:
if ([NSStringFromClass([[viewControlles lastObject] class]) isEqualToString: @"MainViewController"]) {
我尝试在btn中的选择器goToNextView中进行回调
[self performSelector:@selector(goToNextView) withObject:self afterDelay:1.0];
不走运。
任何建议。请询问这是否不清楚,因为我有点累了,现在正准备睡觉:)您可以忽略用户交互,直到视图控制器消失:
- (IBAction)themeBtnAction:(id)sender
{
NSString *language = [[OnlineStore sharedStore]getTheLanguage];
[[OnlineStore sharedStore]getTheThemeBaseGuides:language callback:^{
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[self performSegueWithIdentifier:@"from main to themecategory" sender:self];
}]
}
- (void)viewDidDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}
或者以类似方式禁用按钮上的用户交互:
button.userInteractionEnabled = NO;
...
button.userInteractionEnabled = YES;
谢谢你,提摩太!我真的需要这个答案。