-
Notifications
You must be signed in to change notification settings - Fork 0
/
MembershipCardViewController2.m
174 lines (133 loc) · 4.96 KB
/
MembershipCardViewController2.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
//
// MembershipCardViewController2.m
// MembershipCard
//
// Created by mstr on 5/6/14.
// Copyright (c) 2014 com.hbu.com. All rights reserved.
//
#import "MembershipCardViewController2.h"
#import "Cell.h"
#import "OneCardViewController.h"
#import "BadgeInfos.h"
#import "Constants.h"
@interface MembershipCardViewController2 ()
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property(nonatomic,weak) BadgeInfos *badgeInfos;
@end
NSString *kCellId=@"cellID";
NSString *kDetailViewControllerID=@"OneCardView";
@implementation MembershipCardViewController2
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.collectionView setDelegate:self];
[self.collectionView setDataSource:self];
[[self collectionView]setBackgroundColor:[UIColor whiteColor]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark properties
-(void) setIndex:(NSInteger)index{
_index=index;
NSLog(@"index become %ld in collection",(long)_index);
//set the special according the index ; need to be done here
}
-(BadgeInfos *) badgeInfos{
// NSLog(@"getBadgeInfos has been called");
if(_badgeInfos==nil)
_badgeInfos=[BadgeInfos shareInstance];
return _badgeInfos;
}
#pragma mark collectionView datasource
-(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return badgesCountInOnePage;
}
-(NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
Cell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:kCellId forIndexPath:indexPath];
NSLog(@"cellForItemAtIndexPath :index=%ld",(long)self.index);
Badge *badge=[self.badgeInfos badgeAtIndex:(indexPath.row+self.index*badgesCountInOnePage)];
if(badge!=nil){
cell.CellLabel.text=badge.badgeName;
[cell.CellImage setBackgroundImage:[UIImage imageNamed:badge.badgeThumbImage] forState:UIControlStateNormal];
}
else {
cell.CellImage.hidden=YES;
cell.CellLabel.hidden=YES;
}
return cell;
}
#pragma mark UICollectionViewDelegateFlowLayout protocal
-(CGFloat) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
CGRect screenBounds=[[UIScreen mainScreen]bounds];
if(screenBounds.size.height==568) //4 inch
{
return 20.0;
}
else{ //3.5 inch
return 5.0;
}
}
-(CGFloat) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
CGRect screenBounds=[[UIScreen mainScreen]bounds];
if(screenBounds.size.height==568)
{
return 10.0;
}
else{
return 10.0;
}
}
-(UIEdgeInsets) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
CGRect screenBounds=[[UIScreen mainScreen]bounds];
if(screenBounds.size.height==568)
{
return UIEdgeInsetsMake(20, 20, 0, 20);
}
else{
return UIEdgeInsetsMake(9, 20, 0, 20);
}
}
#pragma mark PageView delegate
/**
-(MembershipCardViewController2 *) MembershipCardViewControllerForPageIndex{
return self;
}
-(MembershipCardViewController2 *) initWithPageIndex:(NSInteger)index{
return self;
}
**/
#pragma mark Segue to OneCard
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSLog(@"I am entering prepairing for segue");
if([[segue identifier] isEqualToString:@"showOneCard"]){
if([[segue destinationViewController] isKindOfClass:[OneCardViewController class]]){
NSLog(@"I am in prepair for segue to showOneCard");
[self prepareForShowOneCard:segue sender:sender];
}
}
}
-(void) prepareForShowOneCard:(UIStoryboardSegue *) segue sender:(id) sender{
OneCardViewController *oneCardController=segue.destinationViewController;
if([sender isKindOfClass:[UIButton class]] && [[[sender superview]superview] isKindOfClass:[UICollectionViewCell class]]){
UICollectionViewCell *selectedCell=(UICollectionViewCell *)([sender superview].superview);
NSIndexPath *path=[self.collectionView indexPathForCell:selectedCell];
oneCardController.index=path.row+self.index*badgesCountInOnePage;
}
//NSArray *selectedItem=[self.collectionView indexPathsForSelectedItems];
}
@end