-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListContact.m
executable file
·187 lines (142 loc) · 6.72 KB
/
ListContact.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
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
//
// ListContact.m
// DisasterHelper
//
// Created by Violet on 3/6/14.
// Copyright (c) 2014 Tan (Tharin) T.NGUYEN. All rights reserved.
//
#import "ListContact.h"
#import "AddEmergencyContact.h"
@interface ListContact (){
NSMutableArray *totalString;
NSMutableArray *filteredString;
BOOL isFiltered;
}
@end
@implementation ListContact
@synthesize contactArray, tableview, idEmergencyContact;
@synthesize searchBar;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
AddEmergencyContact *emergencyObject = [[AddEmergencyContact alloc] init];
contactArray = [emergencyObject getAllContactList];
// totalString = [[NSMutableArray alloc] init];
// totalString = contactArray;
NSLog(@"TOTALSTRING IS %@", contactArray);
}
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if(searchText.length == 0){
isFiltered = NO;
}
else{
isFiltered = YES;
filteredString = [[NSMutableArray alloc] init];
for (NSObject *str in totalString){
NSRange stringRange = [[str valueForKey:@"name"] rangeOfString:searchText options:NSCaseInsensitiveSearch];
NSLog(@"StringName is %@", [str valueForKey:@"name"]);
if (stringRange.location != NSNotFound) {
[filteredString addObject:str];
}
}
}
[self.tableview reloadData];
}
-(void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar{
[self.tableview resignFirstResponder];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(isFiltered){
return [filteredString count];
}else{
return [totalString count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIndetifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIndetifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndetifier];
}
if(!isFiltered){
cell.textLabel.text = [[totalString objectAtIndex:indexPath.row] valueForKey:@"name"];
}else{
cell.textLabel.text = [[filteredString objectAtIndex:indexPath.row] valueForKey:@"name"];
}
UIImage *img = [UIImage imageNamed:@"person.ico"];
cell.imageView.image = img;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
AddEmergencyContact *emergencyContact = [self.storyboard instantiateViewControllerWithIdentifier:@"AddEmergencyContact"] ;
if([self.idEmergencyContact isEqualToString:@"one"]){
if(!isFiltered)
{
emergencyContact.contactName1String = [[totalString objectAtIndex:indexPath.row] valueForKey:@"name"];
emergencyContact.phoneName1String = [[totalString objectAtIndex:indexPath.row] valueForKey:@"phone"];
}else{
emergencyContact.contactName1String = [[filteredString objectAtIndex:indexPath.row] valueForKey:@"name"];
emergencyContact.phoneName1String = [[filteredString objectAtIndex:indexPath.row] valueForKey:@"phone"];
}
emergencyContact.contactName2String = self.contactName2String;
emergencyContact.phoneName2String = self.phoneName2String;
emergencyContact.contactName3String = self.contactName3String;
emergencyContact.phoneName3String = self.phoneName3String;
emergencyContact.idEmergencyContact = @"one";
}else if([self.idEmergencyContact isEqualToString:@"two"]){
if(!isFiltered){
emergencyContact.contactName2String = [[totalString objectAtIndex:indexPath.row] valueForKey:@"name"];
emergencyContact.phoneName2String = [[totalString objectAtIndex:indexPath.row] valueForKey:@"phone"];
}else{
emergencyContact.contactName2String = [[filteredString objectAtIndex:indexPath.row] valueForKey:@"name"];
emergencyContact.phoneName2String = [[filteredString objectAtIndex:indexPath.row] valueForKey:@"phone"];
}
emergencyContact.contactName1String = self.contactName1String;
emergencyContact.phoneName1String = self.phoneName1String;
emergencyContact.contactName3String = self.contactName3String;
emergencyContact.phoneName3String = self.phoneName3String;
emergencyContact.idEmergencyContact = @"two";
}else if([self.idEmergencyContact isEqualToString:@"three"]){
if(!isFiltered){
emergencyContact.contactName3String = [[totalString objectAtIndex:indexPath.row] valueForKey:@"name"];
emergencyContact.phoneName3String = [[totalString objectAtIndex:indexPath.row] valueForKey:@"phone"];
}else{
emergencyContact.contactName3String = [[filteredString objectAtIndex:indexPath.row] valueForKey:@"name"];
emergencyContact.phoneName3String = [[filteredString objectAtIndex:indexPath.row] valueForKey:@"phone"];
}
emergencyContact.contactName2String = self.contactName2String;
emergencyContact.phoneName2String = self.phoneName2String;
emergencyContact.contactName1String = self.contactName1String;
emergencyContact.phoneName1String = self.phoneName1String;
emergencyContact.idEmergencyContact = @"three";
}
[self presentViewController:emergencyContact animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)cancelButton:(UIBarButtonItem *)sender{
AddEmergencyContact *emergencyContact = [self.storyboard instantiateViewControllerWithIdentifier:@"AddEmergencyContact"] ;
emergencyContact.contactName1String = self.contactName1String;
emergencyContact.phoneName1String = self.phoneName1String;
emergencyContact.contactName2String = self.contactName2String;
emergencyContact.phoneName2String = self.phoneName2String;
emergencyContact.contactName3String = self.contactName3String;
emergencyContact.phoneName3String = self.phoneName3String;
[self presentViewController:emergencyContact animated:YES completion:nil];
}
@end