CollectionViewExampl ChartExample Created by Makarov Roman on 04 03 15

  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
//
// CollectionViewExample.m
// ChartExample
//
// Created by Makarov Roman on 04.03.15.
// Copyright (c) 2015 Makarov Roman. All rights reserved.
//
#import "CollectionViewExample.h"
#import "InfoBankomatView.h"
#import "XMLReader.h"
@interface CollectionViewExample ()
@end
@implementation CollectionViewExample {
NSMutableArray *array;
NSMutableArray *nameImage;
NSMutableArray *numBankomat;
NSMutableArray *nameBankomat;
NSMutableArray *addressBankomat;
NSMutableArray *arr;
}
@synthesize topMenu;
@synthesize textTitle;
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithRed:40.0f/255.0f green:49.0f/255.0f blue:60.0f/255.0f alpha:1.0];
/* Здаем цвет верхнего навигатора */
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:237.0f/255.0f green:49.0f/255.0f blue:36.0f/255.0f alpha:1.0];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar
setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
self.navigationController.navigationBar.translucent = NO;
/* Устанавливаем название кнопки верхнего меню */
self.navigationController.navigationBar.topItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:self.textTitle style:UIBarButtonItemStyleBordered target:self action:nil];
/* Добавляем кнопку поиска */
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:nil action:nil];
// Настройки SegmentControl
[self.topMenu setFrame: CGRectMake(35, 200, 250, 50)];
//self.segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
[self.topMenu addTarget:self action:@selector(MySegmentControlAction:)forControlEvents:UIControlEventValueChanged];
[self.topMenu setSelectedSegmentIndex:1];
/* Устанавливаем параметры верхнего меню */
UIFont *font = [UIFont boldSystemFontOfSize:10.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
forKey:NSFontAttributeName];
[self.topMenu setTitleTextAttributes:attributes
forState:UIControlStateNormal];
self.topMenu.layer.borderColor = [UIColor colorWithRed:120.0f/255.0f green:116.0f/255.0f blue:116.0f/255.0f alpha:1.0].CGColor;
/* Инициализация массивов */
array = [[NSMutableArray alloc] init];
nameImage = [[NSMutableArray alloc] init];
numBankomat = [[NSMutableArray alloc] init];
nameBankomat = [[NSMutableArray alloc] init];
addressBankomat = [[NSMutableArray alloc] init];
/* Задаем фоновый цвет контроллера */
collectionView.backgroundColor = [UIColor colorWithRed:40.0f/255.0f green:49.0f/255.0f blue:60.0f/255.0f alpha:1.0];
}
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(@"data---%@",[[NSString alloc] initWithData: data encoding:NSASCIIStringEncoding]);
[atmsData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// Окончание загрузки данных
/* Парсинг */
NSError *error1 = nil;
NSDictionary *dict1 = [XMLReader dictionaryForXMLData:atmsData error:&error1];
/* Получение массива банкоматов */
arr = dict1[@"response"][@"body"][@"atms"][@"atm"];
for (int i = 0; i < arr.count; i++) {
NSDictionary *arr1 = [arr objectAtIndex:i];
NSString *name = arr1[@"name"][@"text"];
NSString *adress = arr1[@"address"][@"text"];
NSString *num = arr1[@"id"][@"text"];
NSString *state = arr1[@"status"][@"text"];
[numBankomat addObject:num];
[nameBankomat addObject:name];
[addressBankomat addObject:adress];
int status = [state intValue];
switch (status) {
case 0:
[nameImage addObject:@"signGreen@3x.png"];
break;
case 1:
[nameImage addObject:@"signYellow@3x.png"];
break;
case 2:
[nameImage addObject:@"signRed@3x.png"];
break;
}
}
[collectionView reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)MySegmentControlAction:(UISegmentedControl *)segment
{
NSComparator compare = ^(NSString *obj1, NSString *obj2) {
return [obj1 compare:obj2 options:NSCaseInsensitiveSearch];
};
switch (segment.selectedSegmentIndex) {
case 1: {
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name"
ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray;
// sortedArray = [arr sortedArrayUsingDescriptors:sortDescriptors];
break;
}
default:
break;
}
}
#pragma mark Collection View Method
-(NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [nameBankomat count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
UILabel *label = (UILabel *)[cell viewWithTag:100];
label.text = [nameBankomat objectAtIndex:indexPath.row];
UILabel *labelAddress = (UILabel *)[cell viewWithTag:300];
labelAddress.text = [addressBankomat objectAtIndex:indexPath.row];
UILabel *labelNum = (UILabel *)[cell viewWithTag:500];
labelNum.text = [numBankomat objectAtIndex:indexPath.row];
UIImageView *image = (UIImageView *)[cell viewWithTag:200];
image.image = [UIImage imageNamed: [nameImage objectAtIndex:indexPath.row]];
cell.backgroundColor=[UIColor colorWithRed:67.0f/255.0f green:68.0f/255.0f blue:73.0f/255.0f alpha:1.0];
[cell.layer setBorderWidth:1.5f];
[cell.layer setBorderColor:[UIColor colorWithRed:120.0f/255.0f green:116.0f/255.0f blue:116.0f/255.0f alpha:1.0].CGColor];
[cell.layer setCornerRadius:5.0f];
return cell;
}
- (void)_collectionView:(UICollectionView *)_collectionView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Click cell collection view");
InfoBankomatView *infoController = [self.storyboard instantiateViewControllerWithIdentifier:@"InfoBankomatView"];
[self.navigationController pushViewController:infoController animated:YES];
}
/*
#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.
}
*/
@end