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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//
// TAPBaseViewController.m
// Moselo
//
// Created by Ritchie Nathaniel on 2/23/16.
// Copyright © 2016 Moselo. All rights reserved.
//
#import "TAPBaseViewController.h"
#import <AFNetworking/AFNetworking.h>
#import "TAPPopUpInfoViewController.h"
@interface TAPBaseViewController () <TAPPopUpInfoViewControllerDelegate>
@property (strong, nonatomic) UIImage *navigationShadowImage;
- (void)backButtonDidTapped;
- (void)closeButtonDidTapped;
@end
@implementation TAPBaseViewController
#pragma mark - Lifecycle
- (void)loadView {
[super loadView];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
// [[NSNotificationCenter defaultCenter] addObserver:self
// selector:@selector(reachabilityDidChange:)
// name:AFNetworkingReachabilityDidChangeNotification
// object:nil];
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:[TAPUtil getColor:TAP_COLOR_BLACK_44],
NSFontAttributeName:[UIFont fontWithName:TAP_FONT_NAME_BOLD size:17.0f]}];
//WK Note - To remove line under navigation bar
self.navigationController.navigationBar.backgroundColor = [UIColor whiteColor];
self.navigationController.navigationBar.layer.shadowColor = [TAPUtil getColor:@"D9D9D9"].CGColor;
self.navigationController.navigationBar.layer.shadowOffset = CGSizeMake(0.0, 1.0f);
self.navigationController.navigationBar.layer.shadowRadius = 1.0;
self.navigationController.navigationBar.layer.shadowOpacity = 0.4;
_navigationShadowImage = self.navigationController.navigationBar.shadowImage;
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
//End Note
//WK Note - To show line under navigation bar
// [self.navigationController.navigationBar setShadowImage:self.navigationShadowImage];
//End Note
self.navigationController.navigationBar.translucent = NO;
}
- (void)viewDidUnload {
[super viewDidUnload];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:AFNetworkingReachabilityDidChangeNotification
object:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
#ifdef DEBUG
NSLog(@"Screen: %@", [self.class description]);
#endif
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
self.automaticallyAdjustsScrollViewInsets = NO;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}
#pragma mark - Delegate
#pragma TAPPopUpInfoViewController
- (void)popUpInfoViewControllerDidTappedLeftButton {
[self popUpInfoDidTappedLeftButton];
}
- (void)popUpInfoViewControllerDidTappedSingleButtonOrRightButton {
[self popUpInfoTappedSingleButtonOrRightButton];
}
#pragma mark - Custom Method
- (void)keyboardWillShow:(NSNotification *)notification {
CGFloat keyboardHeight = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
[self keyboardWillShowWithHeight:keyboardHeight];
}
- (void)keyboardWillHide:(NSNotification *)notification {
CGFloat keyboardHeight = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
[self keyboardWillHideWithHeight:keyboardHeight];
}
- (void)keyboardWillShowWithHeight:(CGFloat)keyboardHeight {
}
- (void)keyboardWillHideWithHeight:(CGFloat)keyboardHeight {
}
- (void)reachabilityDidChange:(NSNotification *)notification {
BOOL reachable;
NSString *status = [notification.userInfo objectForKey:AFNetworkingReachabilityNotificationStatusItem];
NSInteger statusValue = [status integerValue];
switch(statusValue)
{
case 0:
//AFNetworkReachabilityStatusNotReachable
reachable = NO;
break;
case 1:
//AFNetworkReachabilityStatusReachableViaWWAN
reachable = YES;
break;
case 2:
//AFNetworkReachabilityStatusReachableViaWiFi
reachable = YES;
break;
default:
//AFNetworkReachabilityStatusUnknown
reachable = NO;
break;
}
[self reachabilityChangeIsReachable:reachable];
}
- (void)reachabilityChangeIsReachable:(BOOL)reachable {
}
- (void)showCustomBackButton {
UIImage *buttonImage = [UIImage imageNamed:@"TAPIconBackArrow" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 40.0f, 40.0f)];
button.contentEdgeInsets = UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 18.0f);
[button setImage:buttonImage forState:UIControlStateNormal];
[button addTarget:self action:@selector(backButtonDidTapped) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setLeftBarButtonItem:barButtonItem];
}
- (void)backButtonDidTapped {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)showCustomCloseButton {
UIImage *buttonImage = [UIImage imageNamed:@"TAPIconCloseGreen" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 40.0f, 40.0f)];
button.contentEdgeInsets = UIEdgeInsetsMake(0.0f, 18.0f, 0.0f, 0.0f);
[button setImage:buttonImage forState:UIControlStateNormal];
[button addTarget:self action:@selector(closeButtonDidTapped) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setRightBarButtonItem:barButtonItem];
}
- (void)closeButtonDidTapped {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)showPopupViewWithPopupType:(TAPPopUpInfoViewControllerType)type title:(NSString *)title detailInformation:(NSString *)detailInfo {
TAPPopUpInfoViewController *popupInfoViewController = [[TAPPopUpInfoViewController alloc] init];
popupInfoViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
popupInfoViewController.delegate = self;
[popupInfoViewController setPopUpInfoViewControllerType:type withTitle:title detailInformation:detailInfo];
[self presentViewController:popupInfoViewController animated:NO completion:^{
}];
}
- (void)popUpInfoDidTappedLeftButton {
}
- (void)popUpInfoTappedSingleButtonOrRightButton {
}
@end