-
Notifications
You must be signed in to change notification settings - Fork 0
/
TesListViewController.m
executable file
·201 lines (163 loc) · 8.82 KB
/
TesListViewController.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//
// TesListViewController.m
// Login
//
// Created by Dev on 10/27/14.
// Copyright (c) 2014 Dev. All rights reserved.
//
#import "TesListViewController.h"
#import "SchoolTableViewCell.h"
@interface TesListViewController (){
NSArray *schools;
NSArray *filteredSchools;
NSArray *follows;
}
@end
@implementation TesListViewController
-(void)viewWillAppear:(BOOL)animated{
self.noResults.layer.opacity = 0.0;
follows = [PFUser currentUser][@"follows"];
[self setup];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
}
-(void)setup{
PFQuery *querySchools = [PFQuery queryWithClassName:@"SchoolsNames"];
[querySchools whereKey:@"Available" equalTo:[NSNumber numberWithBool:YES]];
[querySchools orderByAscending:@"Name"];
schools = [NSMutableArray arrayWithArray:[querySchools findObjects]];
// for(int i =0; i < schools.count; i++){
//
// NSLog(@"School: %s",[[schools objectAtIndex:i][@"Name"] UTF8String]);
// }
[self.tableView reloadData];
self.headerView.backgroundColor = [UIColor colorWithRed:59/255.0 green:65/255.0 blue:66/255.0 alpha:1];
}
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapRecog)];
[self.view addGestureRecognizer:tap];
[self.view setBackgroundColor:[UIColor colorWithRed:44/255.0 green:51/255.0 blue:52/255.0 alpha:0.95]];
UIColor *greySearch = [UIColor colorWithRed:142/255.0 green:142/255.0 blue:147/255.0 alpha:1];
UIColor *whiteSearch = [UIColor whiteColor];
self.searchBox.attributedText = [[NSAttributedString alloc] initWithString:@"" attributes:@{NSForegroundColorAttributeName: whiteSearch}];
self.searchBox.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Search" attributes:@{NSForegroundColorAttributeName: greySearch}];
self.searchBox.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:17.0f];
[self.searchBox addTarget:self action:@selector(textChanged:) forControlEvents:UIControlEventEditingChanged];
[self.searchBox setDelegate:self];
[self.tableView setBackgroundColor:[UIColor clearColor]];
[self.tableView setDelegate:self];
[self.tableView setDataSource:self];
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
-(void)tapRecog{
[self.searchBox resignFirstResponder];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
follows = [PFUser currentUser][@"follows"];
SchoolTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SchoolCell" forIndexPath:indexPath];
if(self.searchBox.text.length > 0 ){
// NSLog(@"Count: %d ",filteredSchools.count);
if([follows containsObject:[filteredSchools objectAtIndex:indexPath.row][@"Name"]]){
//cell.name.textColor = [UIColor redColor];
cell.tag = 1;
[cell.followButton setTitle:@"Scouting" forState:UIControlStateNormal];
[cell.followButton setBackgroundImage:[UIImage imageNamed:@"following_bttn.png"] forState:UIControlStateNormal];
}else{
// cell.name.textColor = [UIColor whiteColor];
cell.tag = 0;
[cell.followButton setTitle:@"Prospect" forState:UIControlStateNormal];
[cell.followButton setBackgroundImage:[UIImage imageNamed:@"follow_bttn.png"] forState:UIControlStateNormal];
}
cell.name.text = [filteredSchools objectAtIndex:indexPath.row][@"Name"];
}else{
if([follows containsObject:[schools objectAtIndex:indexPath.row][@"Name"]]){
//cell.name.textColor = [UIColor redColor];
cell.tag = 1;
[cell.followButton setTitle:@"Scouting" forState:UIControlStateNormal];
[cell.followButton setBackgroundImage:[UIImage imageNamed:@"following_bttn.png"] forState:UIControlStateNormal];
}else{
// cell.name.textColor = [UIColor whiteColor];
cell.tag = 0;
[cell.followButton setTitle:@"Prospect" forState:UIControlStateNormal];
[cell.followButton setBackgroundImage:[UIImage imageNamed:@"follow_bttn.png"] forState:UIControlStateNormal];
}
cell.name.text = [schools objectAtIndex:indexPath.row][@"Name"];
}
cell.followButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:17.0];
// [myButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:13.0]];
cell.followButton.tag = indexPath.row;
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(filteredSchools.count == 0 && self.searchBox.text.length > 0){
self.noResults.layer.opacity = 1.0;
}else{
self.noResults.layer.opacity = 0.0;
}
if(self.searchBox.text.length > 0){
return filteredSchools.count;
}else
return schools.count;
}
- (void) orientationChanged:(NSNotification *)note
{
//NSLog(@"Orientation Changed! from view");
UIDevice * device = note.object;
switch(device.orientation)
{
case UIDeviceOrientationPortrait:
/* start special animation */
//self.tableView.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"list_background.png"]];
//self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"List_LandscapeBG.png"]];
// self.view.layer.contents = (id)[UIImage imageNamed:@"List_LandscapeBG.png"].CGImage;
// self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"list_background.png"]];
//[self.MenWomenController setFrame:CGRectMake(-1, 63, self.view.layer.frame.size.width+3,self.MenWomenController.frame.size.height)];
// self.tableView.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"list_background.png"]];
// [self.tableView setFrame:CGRectMake(0, (self.MenWomenController.frame.origin.y + self.MenWomenController.frame.size.height)-1,self.tableView.frame.size.width, self.tableView.frame.size.height) ];
//printf("-->+: %f \n",(self.MenWomenController.frame.origin.y + self.MenWomenController.frame.size.height));
break;
case UIDeviceOrientationLandscapeRight:
case UIDeviceOrientationLandscapeLeft:
//printf("-->: %f \n",(self.MenWomenController.frame.origin.y + self.MenWomenController.frame.size.height));
// self.tableView.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
// printf("%d \n",self.MenWomenController.frame.origin.x);
// self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"List_LandscapeBG.png"]];
//
// [self.MenWomenController setFrame:CGRectMake(-1, self.navigationController.navigationBar.frame.size.height + (self./MenWomenController.frame.size.height/2)-2, self.view.layer.frame.size.width+3 , self.MenWomenController.frame.size.height)];
//printf("-->: %f \n",(self.MenWomenController.frame.origin.y + self.MenWomenController.frame.size.height));
// [self.tableView setFrame:CGRectMake(0, (self.MenWomenController.frame.origin.y + self.MenWomenController.frame.size.height)-1,self.tableView.frame.size.width, self.tableView.frame.size.height) ];
// self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"list_background.png"]];
//self.tableView.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"List_LandscapeBG.png"]];
break;
default:
break;
};
}
/*
#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.
}
*/
-(void)textFieldDidBeginEditing:(UITextField *)textField{
}
-(void)textChanged:(UITextField *)textfield{
follows = [PFUser currentUser][@"follows"];
filteredSchools = [schools filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"Name contains[c] %@", self.searchBox.text]];
//NSLog(@"Changing and %d",filteredSchools.count);
[self.tableView reloadData];
}
@end