0

我有一个按钮:

- (IBAction)themeBtnAction:(id)sender
{
    NSString *language = [[OnlineStore sharedStore]getTheLanguage];
        [[OnlineStore sharedStore]getTheThemeBaseGuides:language callback:^{
        [self performSegueWithIdentifier:@"from main to themecategory" sender:self];
    }]
}

但是当用户碰巧双击按钮时,它会导致崩溃。可能是因为下一个 viewcontroller 被加载到堆上两次(我的猜测),当我尝试UINavigationController从那一秒返回 pop时收到的错误消息UIViewController是:Unbalanced calls to begin/end appearance transitions for <MySecondViewController: 0xb257b80>.

我该怎么做才能防止这种情况发生?

我试图把它放在回调内:

    if ([NSStringFromClass([[viewControlles lastObject] class]) isEqualToString: @"MainViewController"]) {

我试图在 btn 的选择器 goToNextView 中进行回调

   [self performSelector:@selector(goToNextView)  withObject:self afterDelay:1.0];

没运气。有什么建议么。请询问这是否不清楚,因为我有点累,现在正要睡觉:)

4

1 回答 1

1

您可以忽略用户交互,直到视图控制器消失:

- (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;
于 2013-11-07T01:41:31.200 回答