-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsEditRoleViewController.m
executable file
·129 lines (106 loc) · 4.21 KB
/
SettingsEditRoleViewController.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// SettingsEditRoleViewController.m
// Junction
//
// Created by Bobby Ren on 4/8/13.
//
//
#import "SettingsEditRoleViewController.h"
#import "AppDelegate.h"
#import "IndustryFilterTableViewController.h"
static AppDelegate * appDelegate;
@interface SettingsEditRoleViewController ()
@end
@implementation SettingsEditRoleViewController
@synthesize delegate;
@synthesize roleIndex, industry, position, company;
- (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.
// make a custom header label
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 = @"Add Role";
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];
UIBarButtonItem * saveButton = [[UIBarButtonItem alloc] initWithCustomView:buttonSave];
[self.navigationItem setRightBarButtonItem:saveButton];
tableView.backgroundColor = COLOR_FAINTBLUE;
if (self.position)
[inputPosition setText:self.position];
if (self.company)
[inputCompany setText:self.company];
if (self.industry)
[inputIndustry setText:self.industry];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)goBack:(id)sender {
// dismiss
[self.navigationController popViewControllerAnimated:YES];
}
-(IBAction)didClickSave:(id)sender {
NSLog(@"Saved!");
[delegate didSaveRoleAtIndex:self.roleIndex withPosition:inputPosition.text withCompany:inputCompany.text withIndustry:inputIndustry.text];
}
// todo: check ios5 vs ios6 behavior
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
NSLog(@"Start editing");
if (textField == inputIndustry) {
IndustryFilterTableViewController * industryFilterTable = [[IndustryFilterTableViewController alloc] init];
[industryFilterTable setDelegate:self];
[self.navigationController pushViewController:industryFilterTable animated:YES];
return NO;
}
return YES;
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
if (textField == inputPosition)
[inputCompany becomeFirstResponder];
else if (textField == inputCompany)
[inputIndustry becomeFirstResponder];
return YES;
}
-(void)textFieldDidEndEditing:(UITextField *)textField {
[textField resignFirstResponder];
}
#pragma mark IndustryFieldDelegate
-(void)didSelectIndustryFilter:(NSString *)industry {
[self.navigationController popToViewController:self animated:YES];
[inputIndustry resignFirstResponder];
inputIndustry.text = industry;
}
@end