UIAlertView ClickedButtonAtIndex不会保存整数

时间:2013-02-10 20:20:08

标签: ios cocoa-touch

我已经制作了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];
}

为什么不保存?

1 个答案:

答案 0 :(得分:0)

UIAlertViewDelegate方法称为alertView:clickedButtonAtIndex:而不是alertViewReset:clickedButtonAtIndex:

你的函数alertViewReset:clickedButtonAtIndex:永远不会被调用。更正名称,它应该没问题。