0

我已经制作了一个UIAlertView其中的第二个按钮应该将分数重置回 0。

这是我的 UIAlertView 代码:

- (IBAction)showActionSheetReset:(id)sender
{
    UIAlertView *resetAlertView = [[UIAlertView alloc] initWithTitle:@"Delete And Reset Score"
                                                         message:@"Are You sure You Want To Reset The Score Shown on the Engligh Page? This WILL NOT affect your High Score on Game Center."
                                                        delegate:self
                                               cancelButtonTitle:@"No, Don't Erase"
                                               otherButtonTitles:@"Yes, Reset Score", nil];

    [resetAlertView show];
    resetAlertView.tag = 2;
}

- (void)alertViewReset:(UIAlertView *)alertViewReset clickedButtonAtIndex:       (NSInteger)buttonIndex
{
    if (alertViewReset.tag == 2) {
        if (buttonIndex == 1) {
            [self resetTheScore];

        }
    }
}

这是我的resetTheScore方法:

- (IBAction)resetTheScore
{
    self.currentScore = 0;
    currentScoreLabel.text = [NSString stringWithFormat:@"%lld", self.currentScore];
    [self counterDefaults:self];
}

这是我的counterDefaults方法:

- (IBAction)counterDefaults:(id)sender
{
    NSUserDefaults *Defaults = [NSUserDefaults standardUserDefaults];
    [Defaults setInteger:self.currentScore forKey:TapCount];
    [Defaults synchronize];
}

为什么不保存?

4

1 回答 1

0

UIAlertViewDelegate方法称为alertView:clickedButtonAtIndex:not alertViewReset:clickedButtonAtIndex:

你的函数alertViewReset:clickedButtonAtIndex:永远不会被调用。改正名字应该没问题。

于 2013-02-10T20:41:40.493 回答