-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsEditPersonalViewController.m
More file actions
executable file
·95 lines (80 loc) · 3.18 KB
/
SettingsEditPersonalViewController.m
File metadata and controls
executable file
·95 lines (80 loc) · 3.18 KB
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
94
95
//
// SettingsEditPersonalViewController.m
// Junction
//
// Created by Bobby Ren on 4/7/13.
//
//
#import "SettingsEditPersonalViewController.h"
#import "AppDelegate.h"
static AppDelegate * appDelegate;
@interface SettingsEditPersonalViewController ()
@end
@implementation SettingsEditPersonalViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
UIImage * headerbg = [UIImage imageNamed:@"header_bg"];
[self.navigationController.navigationBar setBackgroundImage:headerbg forBarMetrics:UIBarMetricsDefault];
UILabel * titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[titleView setFont:[UIFont boldSystemFontOfSize:23]];
[titleView setTextColor:[UIColor whiteColor]];
[titleView setBackgroundColor:[UIColor colorWithRed:14.0/255.0 green:158.0/255.0 blue:205.0/255.0 alpha:1]];
[titleView setTextAlignment:NSTextAlignmentCenter];
titleView.text = @"Personal";
UIFont * font = titleView.font;
CGRect frame = CGRectMake(0, 0, [self.navigationItem.title sizeWithFont:font].width, 44);
frame.origin.x = 320 - frame.size.width / 2;
[titleView setFrame:frame];
self.navigationItem.titleView = titleView;
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"icon-back"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(10, 0, 30, 30)];
UIBarButtonItem * backbutton = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setLeftBarButtonItem:backbutton];
self.view.backgroundColor = COLOR_FAINTBLUE;
UserInfo * myUserInfo = appDelegate.myUserInfo;
textFieldName.text = myUserInfo.username;
textFieldEmail.text = myUserInfo.email;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark UITextFieldDelegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
// don't save here
return YES;
}
-(void)goBack:(id)sender {
// save
UserInfo * myUserInfo = appDelegate.myUserInfo;
myUserInfo.username = textFieldName.text;
myUserInfo.email = textFieldEmail.text;
[[myUserInfo toPFObject] saveEventually:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSLog(@"Personal information Updated!");
[[NSNotificationCenter defaultCenter] postNotificationName:kMyUserInfoDidChangeNotification object:nil];
}
else {
NSLog(@"Saving personal information error: %@", error);
}
}];
// dismiss
[self.navigationController popViewControllerAnimated:YES];
}
@end