我已经制作了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];
}
为什么不保存?
答案 0 :(得分:0)
UIAlertViewDelegate
方法称为alertView:clickedButtonAtIndex:
而不是alertViewReset:clickedButtonAtIndex:
。
你的函数alertViewReset:clickedButtonAtIndex:
永远不会被调用。更正名称,它应该没问题。