Guest User

Untitled

a guest
Jan 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. - (IBAction)vote:(id)sender
  2. {
  3. UIButton * button = (UIButton *) sender;
  4. int num;
  5.  
  6. PFUser * currentUser = [PFUser currentUser];
  7. NSMutableDictionary * voters = [[[NSMutableDictionary alloc] initWithDictionary:[self.voteInfo objectForKey:@"voters"]] autorelease];
  8.  
  9. NSMutableDictionary * voteInfo = [[[NSMutableDictionary alloc] init] autorelease];
  10. if ([self.note length] > 0)
  11. [voteInfo setObject:self.note forKey:@"note"];
  12.  
  13. if (self.imageData)
  14. [voteInfo setObject:self.imageData forKey:@"image"];
  15.  
  16. if (button.tag == 5){
  17. num = [[self.voteInfo objectForKey:@"yes"] intValue] + 1;
  18. [self.voteInfo setObject:[NSNumber numberWithInt:num] forKey:@"yes"];
  19. [voteInfo setObject:@"yes" forKey:@"option"];
  20. [voters setObject:voteInfo forKey:currentUser.username];
  21. [self.yes setImage:[UIImage imageNamed:@"YesSelected.png"] forState:UIControlStateNormal];
  22. [self.no setImage:[UIImage imageNamed:@"NoNOTSelected.png"] forState:UIControlStateNormal];
  23. }else if (button.tag == 10){
  24. num = [[self.voteInfo objectForKey:@"no"] intValue] + 1;
  25. [self.voteInfo setObject:[NSNumber numberWithInt:num] forKey:@"no"];
  26. [voteInfo setObject:@"no" forKey:@"option"];
  27. [voters setObject:voteInfo forKey:currentUser.username];
  28. [self.yes setImage:[UIImage imageNamed:@"YesNOTSelected.png"] forState:UIControlStateNormal];
  29. [self.no setImage:[UIImage imageNamed:@"NoSelected.png"] forState:UIControlStateNormal];
  30. }
  31.  
  32. [self.yes setEnabled:NO];
  33. [self.no setEnabled:NO];
  34. [self.voteInfo setObject:voters forKey:@"voters"];
  35.  
  36. if ([[[PFUser currentUser] username] isEqualToString:(((PFUser *)[self.voteInfo objectForKey:@"creator"]).username)] == false){
  37. PFQuery *query = [PFQuery queryWithClassName:@"Score"];
  38. [query whereKey:@"username" equalTo:((PFUser *)[self.voteInfo objectForKey:@"creator"]).username];
  39.  
  40. PFObject * score = [[query findObjects] objectAtIndex:0];
  41. int updatedScore = [[score objectForKey:@"score"] intValue] + 5;
  42. [score setObject:[NSNumber numberWithInt:updatedScore] forKey:@"score"];
  43. [score saveInBackground];
  44. }
  45.  
  46. //[self.voteInfo saveInBackground];
  47.  
  48.  
  49. [self.voteInfo saveInBackgroundWithBlock:^(BOOL succeeded, NSError * error)
  50. {
  51. if (succeeded){
  52. NSLog(@"Successfully saving your result");
  53. //[self.navigationController popToRootViewControllerAnimated:YES];
  54. } else {
  55. NSLog(@"Error is %@", [error userInfo]);
  56. }
  57. }];
  58.  
  59. }
Add Comment
Please, Sign In to add comment