If-Else声明不读

时间:2015-02-02 23:06:07

标签: ios objective-c parse-platform

我正在使用Parse.com为用户加载一定数量的积分。当用户兑换他们的积分时,如果他有足够的分数,该应用程序应该减去他的积分数量,但由于某种原因,该应用程序说用户总是没有足够的积分,即使显示的点数是足够的。这是代码..

if (alertView.tag == TAG_GOODIEBAG) {

    NSLog (@"user ID:%@", [[PFUser currentUser] objectId]);

    PFQuery *query = [PFUser query];
    [query getObjectInBackgroundWithId:[[PFUser currentUser] objectId] block:^(PFObject *points, NSError *error) {
        // Do something with the returned PFObject in the gameScore variable.


        int score = [[points objectForKey:@"Points"] intValue];

        int finalpoints = score - 250;

        if (finalpoints << 0) {
            UIAlertView *alertnoerror = [[UIAlertView alloc]
                                         initWithTitle:@"Insufficient Points"
                                         message:@"You don't have enough points to redeem this item."
                                         delegate:self
                                         cancelButtonTitle:@"Dismiss"
                                         otherButtonTitles:nil];
            [alertnoerror show];
        }

        else {

        NSLog(@"%d", finalpoints);
        NSString *finalamountofpoints = [NSString stringWithFormat:@"Points: %d", finalpoints];

        label.text = finalamountofpoints;

        int goodiebagpoints = [[points objectForKey:@"GoodieBag"] intValue];

        int finalgoodiebagpoints = goodiebagpoints + 1;

        NSLog(@"%d", finalgoodiebagpoints);

        id var = [NSNumber numberWithInteger: finalpoints];
        id goodiebagid = [NSNumber numberWithInteger:finalgoodiebagpoints];
        points[@"Points"] = var;
        points[@"GoodieBag"] = goodiebagid;
        [points saveInBackground];

        if (!error) {
            UIAlertView *alertnoerror = [[UIAlertView alloc]
                                            initWithTitle:@"Success!"
                                            message:@"You have successfully redeemed your points for your Goodie Bag! Visit our office to receive your prize!"
                                            delegate:self
                                            cancelButtonTitle:@"Dismiss"
                                            otherButtonTitles:nil];
            [alertnoerror show];
        }
        }
                }];

    }

1 个答案:

答案 0 :(得分:4)

对于除if (finalpoints << 0)之外的所有内容,

0将返回true。

你可能意味着:

if (finalpoints < 0)

仅当finalpoints某个值小于零时才会返回true。

finalpoints << 0finalpoints左侧零位的所有位移位。因此,只要finalpoints非零,它就会在转变后保持非零,并评估为YES