-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAcceptInviteViewController.m
93 lines (72 loc) · 2.8 KB
/
AcceptInviteViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// AcceptInviteViewController.m
// MemoryCapsule
//
// Created by Gonzalo Parajon on 3/26/13.
// Copyright (c) 2013 teambrown. All rights reserved.
//
#import "AcceptInviteViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface AcceptInviteViewController ()
@end
@implementation AcceptInviteViewController
@synthesize inviteCode;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self customizeInputFields];
}
- (IBAction)confirmInvite:(id)sender {
NSLog(@"Confirm invite button pressed");
NSLog(@"invite code: %@", self.inviteCode.text);
PFUser *user = [PFUser currentUser];
//get new friend's name
PFUser * newFriend = [PFQuery getUserObjectWithId:self.inviteCode.text];
if(newFriend != nil){
NSString * newFriendName = [newFriend username];
//Add new friend to our list of friends
PFQuery * friendsQuery = [PFQuery queryWithClassName:@"FriendsList"];
[friendsQuery whereKey:@"userName" equalTo:[user username]];
PFObject * friendsList = [friendsQuery getFirstObject];
[friendsList addUniqueObjectsFromArray:[NSArray arrayWithObjects:newFriendName,nil] forKey:@"friends"];
[friendsList saveInBackground];
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Done!"
message:[NSString stringWithFormat: @"You have successfully added '%@' to your list of friends.",newFriendName]
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
[message show];
[self performSelector:@selector(dismissAlertViewAndReturn:) withObject:message afterDelay:2];
}
}
-(void)dismissAlertViewAndReturn:(UIAlertView *)alertView{
[alertView dismissWithClickedButtonIndex:0 animated:YES];
[self.navigationController popViewControllerAnimated:YES];
}
-(void) customizeInputFields{
//UITextField * invitationCode = self.view.subviews[1];
[inviteCode.layer setBackgroundColor: [[UIColor whiteColor] CGColor]];
[inviteCode.layer setBorderColor: [[UIColor grayColor] CGColor]];
[inviteCode.layer setBorderWidth: 1.0];
[inviteCode.layer setCornerRadius:8.0f];
[inviteCode.layer setMasksToBounds:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end