Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (IBAction)vote:(id)sender
- {
- UIButton * button = (UIButton *) sender;
- int num;
- PFUser * currentUser = [PFUser currentUser];
- NSMutableDictionary * voters = [[[NSMutableDictionary alloc] initWithDictionary:[self.voteInfo objectForKey:@"voters"]] autorelease];
- NSMutableDictionary * voteInfo = [[[NSMutableDictionary alloc] init] autorelease];
- if ([self.note length] > 0)
- [voteInfo setObject:self.note forKey:@"note"];
- if (self.imageData)
- [voteInfo setObject:self.imageData forKey:@"image"];
- if (button.tag == 5){
- num = [[self.voteInfo objectForKey:@"yes"] intValue] + 1;
- [self.voteInfo setObject:[NSNumber numberWithInt:num] forKey:@"yes"];
- [voteInfo setObject:@"yes" forKey:@"option"];
- [voters setObject:voteInfo forKey:currentUser.username];
- [self.yes setImage:[UIImage imageNamed:@"YesSelected.png"] forState:UIControlStateNormal];
- [self.no setImage:[UIImage imageNamed:@"NoNOTSelected.png"] forState:UIControlStateNormal];
- }else if (button.tag == 10){
- num = [[self.voteInfo objectForKey:@"no"] intValue] + 1;
- [self.voteInfo setObject:[NSNumber numberWithInt:num] forKey:@"no"];
- [voteInfo setObject:@"no" forKey:@"option"];
- [voters setObject:voteInfo forKey:currentUser.username];
- [self.yes setImage:[UIImage imageNamed:@"YesNOTSelected.png"] forState:UIControlStateNormal];
- [self.no setImage:[UIImage imageNamed:@"NoSelected.png"] forState:UIControlStateNormal];
- }
- [self.yes setEnabled:NO];
- [self.no setEnabled:NO];
- [self.voteInfo setObject:voters forKey:@"voters"];
- if ([[[PFUser currentUser] username] isEqualToString:(((PFUser *)[self.voteInfo objectForKey:@"creator"]).username)] == false){
- PFQuery *query = [PFQuery queryWithClassName:@"Score"];
- [query whereKey:@"username" equalTo:((PFUser *)[self.voteInfo objectForKey:@"creator"]).username];
- PFObject * score = [[query findObjects] objectAtIndex:0];
- int updatedScore = [[score objectForKey:@"score"] intValue] + 5;
- [score setObject:[NSNumber numberWithInt:updatedScore] forKey:@"score"];
- [score saveInBackground];
- }
- //[self.voteInfo saveInBackground];
- [self.voteInfo saveInBackgroundWithBlock:^(BOOL succeeded, NSError * error)
- {
- if (succeeded){
- NSLog(@"Successfully saving your result");
- //[self.navigationController popToRootViewControllerAnimated:YES];
- } else {
- NSLog(@"Error is %@", [error userInfo]);
- }
- }];
- }
Add Comment
Please, Sign In to add comment