/
VertConstrainedSingleSelectViewController.m
executable file
·244 lines (203 loc) · 6.13 KB
/
VertConstrainedSingleSelectViewController.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//
// VertConstrainedSingleSelectViewController.m
// GridViewExamples
//
// Created by gumbright on 8/19/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "VertConstrainedSingleSelectViewController.h"
#import "UIXGridView.h"
#import "UIXGridViewCell.h"
@implementation VertConstrainedSingleSelectViewController
@synthesize currentSelection;
@synthesize overlay;
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
CGRect frame = CGRectMake(0,0,320,416);
UIView* view = [[UIView alloc] initWithFrame:frame];
self.view = view;
// UIXGridView* gv =[[UIXGridView alloc] initWithFrame:frame andStyle:UIXGridViewStyle_VertConstrained selectionType: UIXGridViewSelectionType_Single];
UIXGridView* gv =[[UIXGridView alloc] initWithFrame:frame andStyle:UIXGridViewStyleVertConstrained];
//gv.momentary = NO;
//gv.multiSelect = NO;
gv.gridDelegate = self;
gv.dataSource = self;
gv.backgroundColor = [UIColor whiteColor];
// gv.selectionColor = [UIColor whiteColor];
gv.selectionStyle = UIXGridViewSelectionStyleSingle;
self.title = @"Vert Constr. Single";
// [gv reloadData];
[view addSubview:gv];
[gv release];
}
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
- (UIXGridViewCell*) UIXGridView:(UIXGridView*) gridView cellForIndexPath:(NSIndexPath*) indexPath
{
UIXGridViewCell* cell;
cell = [gridView dequeueReusableCellWithIdentifier:@"VertSingleCell"];
if (cell == nil)
{
cell = [[[UIXGridViewCell alloc] initWithStyle:UIXGridViewCellStyleDefault reuseIdentifier:@"VertSingleCell"] autorelease];
}
switch (indexPath.row)
{
case 0:
{
switch (indexPath.column)
{
case 0:
{
cell.textLabel.text = @"Mercury";
cell.imageView.image = [UIImage imageNamed:@"mercury.jpeg"];
}
break;
case 1:
{
cell.textLabel.text = @"Venus";
cell.imageView.image = [UIImage imageNamed:@"venus.jpeg"];
}
break;
case 2:
{
cell.textLabel.text = @"Earth";
cell.imageView.image = [UIImage imageNamed:@"earth.jpeg"];
}
break;
case 3:
{
cell.textLabel.text = @"Mars";
cell.imageView.image = [UIImage imageNamed:@"mars.jpeg"];
}
break;
case 4:
{
cell.textLabel.text = @"Jupiter";
cell.imageView.image = [UIImage imageNamed:@"jupiter.jpeg"];
}
break;
}
}
break;
case 1:
{
switch (indexPath.column)
{
case 0:
{
cell.textLabel.text = @"Saturn";
cell.imageView.image = [UIImage imageNamed:@"saturn.jpeg"];
}
break;
case 1:
{
cell.textLabel.text = @"Neptune";
cell.imageView.image = [UIImage imageNamed:@"neptune.jpeg"];
}
break;
case 2:
{
cell.textLabel.text = @"Uranus";
cell.imageView.image = [UIImage imageNamed:@"uranus.jpeg"];
}
break;
case 3:
{
cell.textLabel.text = @"Pluto";
cell.imageView.image = [UIImage imageNamed:@"pluto.jpeg"];
}
break;
default:
cell = nil;
break;
}
}
break;
}
// cell.textLabel.highlightedTextColor = cell.textLabel.textColor;
// if ([indexPath isEqual:self.currentSelection])
if ([indexPath compare:self.currentSelection] == NSOrderedSame)
{
// CGRect frame = cell.contentView.frame;
// overlay.frame = frame;
// [cell setOverlayView:overlay];
CGRect frame = cell.contentView.bounds;
UIView* v = [[UIView alloc] initWithFrame:frame];
v.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.50];
UIImageView* iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"redcheck"]];
frame = CGRectMake(v.bounds.size.width - 28, v.bounds.size.height - 28, 28, 28);
iv.frame = frame;
[v addSubview:iv];
[iv release];
[cell setSelectionOverlayView:v];
[v release];
}
return cell;
}
- (NSInteger) numberOfColumnsForGrid:(UIXGridView*) grid
{
return 5;
}
- (NSInteger) numberOfRowsForGrid: (UIXGridView*) grid
{
return 2;
}
- (NSInteger) cellWidthForGrid:(UIXGridView*) grid
{
return 100;
}
- (void) UIXGridView: (UIXGridView*) gridView didSelectCellAtIndexPath:(NSIndexPath*) indexPath
{
// [gridView deselectCellAtIndexPath:indexPath animated:YES];
// [[gridView cellAtIndexPath:currentSelection] setSelectionOverlayView:nil];
self.currentSelection = indexPath;
UIXGridViewCell* cell = [gridView cellAtIndexPath:currentSelection];
CGRect frame = cell.contentView.bounds;
UIView* v = [[UIView alloc] initWithFrame:frame];
v.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.50];
UIImageView* iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"redcheck"]];
frame = CGRectMake(v.bounds.size.width - 28, v.bounds.size.height - 28, 28, 28);
iv.frame = frame;
[v addSubview:iv];
[iv release];
[cell setSelectionOverlayView:v];
[v release];
}
//- (UIColor*) UIXGridView: (UIXGridView*) gridView selectionBackgroundColorForCellAtIndexPath:(NSIndexPath*) indexPath
//{
// return [UIColor orangeColor];
//}
@end