[英]If-Else Statement Not reading
I am using Parse.com to load a certain number of points for a user. 我正在使用Parse.com为用户加载一定数量的点。 When the user redeems their points, the app should subtract that amount of points from him if he has a sufficient amount of points, but for some reason, the app says that the user always has a insufficient amount of points, even though the amount of points shown is a sufficient amount. 当用户赎回他们的积分时,如果他有足够的积分,应用程序应该从他减去该积分数量,但是由于某种原因,该应用程序说用户总是积分不足,即使显示的积分足够。 Here is the code.. 这是代码。
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)
will return true for everything except 0
. if (finalpoints << 0)
对于除0
以外的所有值都将返回true。
You probably meant: 您可能的意思是:
if (finalpoints < 0)
which will return true only when finalpoints
is some value less than zero. 仅当finalpoints
点的值小于零时才返回true。
finalpoints << 0
shifts all of the bits in finalpoints
left zero places. finalpoints << 0
改变所有的位finalpoints
左零个地方。 So as long as finalpoints
is non-zero, it will remain non-zero after the shift, and evaluate to YES
. 因此,只要finalpoints
点不为零,则移位后它将保持为非零,并求值为YES
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.