Xcode UIAlertview被多次调用

Xcode UIAlertview被多次调用,xcode,uialertview,Xcode,Uialertview,我的应用程序中有以下代码。在视图控制器上,我有两个UIButton控件,每个控件执行不同的操作。当我按下第一个按钮时,我有一个UIAlertView来确认操作。这个很好用。我用同样的方法设置第二个按钮。当我按下第二个按钮时,第一个UIAlertView短暂出现,然后第二个UIAlertView出现。此时它工作正常,但第一个UIAlertView再次出现 如果我完全取出UIAlertViews,只更新视图上的标签以指示按下了哪个按钮,我不会再次调用任何一个按钮,因此我将其与包含UIAlertVie

我的应用程序中有以下代码。在视图控制器上,我有两个UIButton控件,每个控件执行不同的操作。当我按下第一个按钮时,我有一个UIAlertView来确认操作。这个很好用。我用同样的方法设置第二个按钮。当我按下第二个按钮时,第一个UIAlertView短暂出现,然后第二个UIAlertView出现。此时它工作正常,但第一个UIAlertView再次出现


如果我完全取出UIAlertViews,只更新视图上的标签以指示按下了哪个按钮,我不会再次调用任何一个按钮,因此我将其与包含UIAlertViews隔离

有人能指出我的代码中导致这种情况的原因吗?这是密码

- (IBAction)clearInspectionsClicked {

    UIAlertView *alertClear = [[UIAlertView alloc] initWithTitle:@"Please Confirm" 
                                            message:@"Clear out all inspection data?" 
                                            delegate:self 
                                            cancelButtonTitle:@"Clear" 
                                            otherButtonTitles:@"Cancel", nil];
[alertClear show];

}

- (IBAction)loadSampleDataClicked {

    UIAlertView *alertLoad = [[UIAlertView alloc] initWithTitle:@"Please Confirm" 
                                                    message:@"Load Sample data?" 
                                                   delegate:self 
                                          cancelButtonTitle:@"Load" 
                                          otherButtonTitles:@"Cancel", nil];
    [alertLoad show];
}


-(void) alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if ([title isEqualToString:@"Clear"])
    {
        [self clearInspections];
        [self.StatusLabel setText:@"Inspection data has been cleared!"];
    }
    if ([title isEqualToString:@"Load"])
    {
        [self loadSampleData];
        [self.StatusLabel setText:@"Sample data has been loaded!"];
    }
}

您是否有可能将其中一个按钮连接到其中两个操作?在Interface Builder中,可以将多个操作关联到一个给定的控件,这将导致这种确切的行为

如果我取出UIAlertViews,而只是在视图的标签中显示一条状态消息,则只调用一个操作。但是,我将检查调试器以确认这一点。谢谢你的帖子!就这样!谢谢你指出这一点。看了这些动作之后,我注意到第二个按钮连接到了这两个按钮。我删除了错误的动作链接,现在可以正常工作了。有时候解决方案比你想象的要简单!!再次感谢!