我已经制作了一个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];
}
为什么不保存?