-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEarthquakeCollectionViewController.m
152 lines (124 loc) · 5.25 KB
/
EarthquakeCollectionViewController.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
//
// EarthquakeCollectionViewController.m
// Earthquake
//
// Created by Jack Magiera on 2/18/14.
// Copyright (c) 2014 Yuxuan Chen. All rights reserved.
//
#import "EarthquakeCollectionViewController.h"
#import "EarthquakeShakeTableViewController.h"
#import "EarthquakeCollectionCell.h"
@interface EarthquakeCollectionViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *backgroundImageView;
@property (nonatomic, strong) NSArray* StructArray;
@property (nonatomic, strong) NSString* StructNames;
@end
@implementation EarthquakeCollectionViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
#pragma mark -
#pragma mark UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [self.StructArray count];
}
/* Editted by Ethan on 3/3/2014
* Allow the navigation bar to pop up.
*/
- (void) viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillAppear:animated];
}
- (void)viewDidLoad
{
NSData* StructJson = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Structures" ofType:@"json"]];
NSError * error;
self.StructArray = [NSJSONSerialization JSONObjectWithData:StructJson options:0 error:&error];
if (error){
NSLog(@"Error in Structures.json file.");
}
[super viewDidLoad];
/* Editted by Ethan on 3/3/2014
* Change the tint of the navigation bar.
* Change the background image of the page.
*/
UIImage *backgroundImg = [UIImage imageNamed:@"Design-Other_Pages-Background.png"];
self.backgroundImageView.image = backgroundImg;
[self.view sendSubviewToBack:self.backgroundImageView];
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.0f/255.0f green:192.0f/255.0f blue:255.0f/255.0f alpha:1.0f];
self.navigationController.navigationBar.translucent = NO;
/* Editted by Ethan on 3/4/2014
* Reorganize the collection view cells.
*/
UICollectionViewFlowLayout *flow = (UICollectionViewFlowLayout*) self.collectionViewLayout;
flow.sectionInset = UIEdgeInsetsMake(90.0f, 15.0f, 10.0f, 15.0f);
//self.EQImages = [@[@"Bridge-1.png",
// @"Hospital-1.png",
// @"House-1.png"] mutableCopy];
// Do any additional setup after loading the view.
[self.collectionView registerClass:[EarthquakeCollectionCell class] forCellWithReuseIdentifier:@"EQCell"];
}
-(EarthquakeCollectionCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
EarthquakeCollectionCell *eqCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"EQCell" forIndexPath:indexPath];
/*long row = [indexPath row];
* Editted by Ethan on 3/6/2014
* Hard code the earthquake pictures to include
* building type, thereby allowing the
* images to be shown in the correct correspondence.
*
NSString *imgName = self.EQImages[row];
UIImage *img = [UIImage imageNamed:imgName];
NSString *build = [imgName componentsSeparatedByString:@"-"][0];
build = [NSString stringWithFormat:@"%@-",build];
eqCell.eqImageView = [[UIImageView alloc] initWithFrame:eqCell.bounds];
[eqCell addSubview:eqCell.eqImageView];
[eqCell.eqImageView setImage:img];
eqCell.buildingType = build;
*/
eqCell.eqImageView = [[UIImageView alloc] initWithFrame:eqCell.bounds];
[eqCell addSubview:eqCell.eqImageView];
[eqCell.eqImageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@%d%@", [(NSDictionary*)self.StructArray[indexPath.row] objectForKey:@"imgBase"],1,[(NSDictionary*)self.StructArray[indexPath.row] objectForKey:@"imgExt"]]]];
eqCell.buildingType = [(NSDictionary*)self.StructArray[indexPath.row] objectForKey:@"imgBase"];
return eqCell;
}
/* Editted by Ethan on 3/4/2014
* Added segue to the collection view controller.
*/
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - UICollectionViewDelegate
/* Editted by Ethan on 3/6/2014
* Fixed the segue.
*/
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
// TODO: Select Item
[self.collectionView deselectItemAtIndexPath:indexPath animated:YES];
EarthquakeCollectionCell *cell = (EarthquakeCollectionCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
[self performSegueWithIdentifier:@"structure" sender:cell];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"structure"]) {
[(EarthquakeShakeTableViewController *)segue.destinationViewController setBuildingType:[sender buildingType]];
}
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
// TODO: Deselect item
}
@end