UIAlertView如果不够点(cocos2d iPhone)

发布于 2024-11-16 23:07:56 字数 782 浏览 1 评论 0原文

如果用户没有足够的积分来购买升级,我希望弹出 UIAlertView。到目前为止,我有这个代码可以花费积分来获得升级。如果升级需要 300 点,而用户只有 150 点,我希望 UIAlertView 计算所需的金额,并说“抱歉,您还需要 150 点来购买此升级”。这是我的代码。 (“mag”和“score”都是整数。)

    -(int)mag {
    return [[NSUserDefaults standardUserDefaults] integerForKey:kMagDefaultsKey];
}

    -(int)score {
        return [[NSUserDefaults standardUserDefaults] integerForKey:kScoreDefaultsKey];
    }   
    -(void)setMag:(int)value {
        [[NSUserDefaults standardUserDefaults] setInteger:value forKey:kMagDefaultsKey];
    }
    -(void)setScore:(int)value {
        [[NSUserDefaults standardUserDefaults] setInteger:value forKey:kScoreDefaultsKey];
    }
    -(void)plusFiveMag:(id)sender {
        self.mag = self.mag + 5;
        self.score = self.score - 300;
    }   

I want a UIAlertView to popup if the user doesn't have enough points to purchase an upgrade. So far I have this code to spend points to get the upgrade. If the upgrade costs 300 points, and the user only has 150, I would like the UIAlertView to calculate the amount needed and say something like, "Sorry, you need 150 more points to buy this upgrade". Here's my code. ('mag' and 'score' are both ints.)

    -(int)mag {
    return [[NSUserDefaults standardUserDefaults] integerForKey:kMagDefaultsKey];
}

    -(int)score {
        return [[NSUserDefaults standardUserDefaults] integerForKey:kScoreDefaultsKey];
    }   
    -(void)setMag:(int)value {
        [[NSUserDefaults standardUserDefaults] setInteger:value forKey:kMagDefaultsKey];
    }
    -(void)setScore:(int)value {
        [[NSUserDefaults standardUserDefaults] setInteger:value forKey:kScoreDefaultsKey];
    }
    -(void)plusFiveMag:(id)sender {
        self.mag = self.mag + 5;
        self.score = self.score - 300;
    }   

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独岁月 2024-11-23 23:07:56

尝试这样的事情......

  -(void)alertview
    {
    if(self.Mag>self.cost)
    {
    int difference;
    difference=self.Mag-self.cost;
    UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:@"your message" message:differene delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

            [Alert show];
            [Alert release];

}
}

Try somethin like this...

  -(void)alertview
    {
    if(self.Mag>self.cost)
    {
    int difference;
    difference=self.Mag-self.cost;
    UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:@"your message" message:differene delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

            [Alert show];
            [Alert release];

}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文