If-Else 语句未读
If-Else Statement Not reading
我正在使用 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];
}
}
}];
}
if (finalpoints << 0)
将 return 除了 0
.
之外的所有内容都为真
你的意思可能是:
if (finalpoints < 0)
只有当 finalpoints
是小于零的某个值时才会 return 为真。
finalpoints << 0
将 finalpoints
中的所有位移动到左零位置。所以只要 finalpoints
非零,移位后它就会保持非零,并计算为 YES
.
我正在使用 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];
}
}
}];
}
if (finalpoints << 0)
将 return 除了 0
.
你的意思可能是:
if (finalpoints < 0)
只有当 finalpoints
是小于零的某个值时才会 return 为真。
finalpoints << 0
将 finalpoints
中的所有位移动到左零位置。所以只要 finalpoints
非零,移位后它就会保持非零,并计算为 YES
.