-
Notifications
You must be signed in to change notification settings - Fork 0
/
dropDownViewController.m
211 lines (180 loc) · 6.65 KB
/
dropDownViewController.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
//
// dropDownViewController.m
// tableViewDropDownBY
//
// Created by Subramani B R on 7/25/14.
// Copyright (c) 2014 Subramani B R. All rights reserved.
//
#import "dropDownViewController.h"
#import "suggestedTableViewCell.h"
#import "AppDelegate.h"
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define isIPad (([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) ? NO : YES)
@interface dropDownViewController ()
@end
@implementation dropDownViewController
@synthesize checkedData;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
if (!isIPad)
{
self.btn = [[UIButton alloc] initWithFrame:CGRectMake(60,152, 241, 38)];
[self.btn setImage:[UIImage imageNamed:@"arrow_down.png"] forState:UIControlStateNormal];
[self.btn addTarget:self action:@selector(list) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.btn];
self.lblTitle = [[UILabel alloc]initWithFrame:CGRectMake(0,0,211,38)];
self.lblTitle.textColor = [UIColor blackColor];
self.lblTitle.userInteractionEnabled = NO;
self.lblTitle.text = @"Send suggestion";
self.lblTitle.font = [UIFont boldSystemFontOfSize:13.0];
self.lblTitle.textAlignment = NSTextAlignmentLeft;
[self.btn addSubview:self.lblTitle];
CGRect rectFrame=CGRectMake(30, 192,220,0);
self.table=[[UITableView alloc]initWithFrame:rectFrame style:UITableViewStylePlain];
self.table.delegate = self;
self.table.dataSource = self;
[self.view addSubview:self.table];
}
else
{
self.btn = [[UIButton alloc] initWithFrame:CGRectMake(60,152, 241, 38)];
[self.btn setImage:[UIImage imageNamed:@"arrow_down.png"] forState:UIControlStateNormal];
[self.btn addTarget:self action:@selector(list) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.btn];
self.lblTitle = [[UILabel alloc]initWithFrame:CGRectMake(0,0,211,38)];
self.lblTitle.textColor = [UIColor blackColor];
self.lblTitle.userInteractionEnabled = NO;
self.lblTitle.text = @"Send suggestion";
self.lblTitle.font = [UIFont boldSystemFontOfSize:13.0];
self.lblTitle.textAlignment = NSTextAlignmentLeft;
[self.btn addSubview:self.lblTitle];
CGRect rectFrame=CGRectMake(30, 192,220,0);
self.table=[[UITableView alloc]initWithFrame:rectFrame style:UITableViewStylePlain];
self.table.delegate = self;
self.table.dataSource = self;
[self.view addSubview:self.table];
}
}
-(void)list
{
if (self.btn.currentImage == [UIImage imageNamed:@"arrow_down.png"])
{
[self.btn setImage:[UIImage imageNamed:@"arrow_up.png"] forState:UIControlStateNormal];
[UIView animateWithDuration:0.55 animations:^{
self.table.frame=CGRectMake(30, 192,220,250);
} completion:^(BOOL finished) {
NSLog(@"suggestion");
}];
}
else
{
[self.btn setImage:[UIImage imageNamed:@"arrow_down.png"] forState:UIControlStateNormal];
[UIView animateWithDuration:0.55 animations:^{
self.table.frame=CGRectMake(30, 192,220,0);
} completion:^(BOOL finished) {
NSLog(@"suggestion");
}];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
-(NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *Identifier = @"ceelll";
suggestedTableViewCell *cell =(suggestedTableViewCell *) [tableView dequeueReusableCellWithIdentifier:Identifier];
if (cell==nil) {
NSArray *arr;
if (!isIPad) {
arr=[[NSBundle mainBundle]loadNibNamed:@"suggestedTableViewCell" owner:self options:nil];
}
else
{
arr=[[NSBundle mainBundle]loadNibNamed:@"suggestedCell_ipad" owner:self options:nil];
}
cell=[arr objectAtIndex:0];
}
cell.backgroundColor = UIColorFromRGB(0Xd4d4d4);
cell.lblString.text = [NSString stringWithFormat:@"cell %ld",(long)indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// if(self.checkedData != nil && indexPath.row == self.checkedData.row)
// {
// cell.imgae.image=[UIImage imageNamed:@"check_box_on.png"];
// }
// else
// {
// cell.imgae.image=[UIImage imageNamed:@"check_box_off.png"];
// }
if([self.checkedData isEqual:indexPath])
{
cell.image.image=[UIImage imageNamed:@"check_box_on.png"];
}
else
{
cell.image.image=[UIImage imageNamed:@"check_box_off.png"];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(self.checkedData)
{
suggestedTableViewCell* cell =(suggestedTableViewCell*) [tableView
cellForRowAtIndexPath:self.checkedData];
cell.image.image=[UIImage imageNamed:@"check_box_off.png"];
}
if([self.checkedData isEqual:indexPath])
{
self.checkedData = nil;
}
else
{
suggestedTableViewCell* cell =(suggestedTableViewCell*) [tableView
cellForRowAtIndexPath:indexPath];
cell.image.image=[UIImage imageNamed:@"check_box_on.png"];
self.checkedData = indexPath;
}
}
//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
// NSIndexPath *previousSelection = self.checkedData;
// NSArray *array = nil;
// if (nil != previousSelection)
// {
//
// array = [NSArray arrayWithObjects:previousSelection, indexPath, nil];
//
// } else
// {
// array = [NSArray arrayWithObject:indexPath];
// }
//
// self.checkedData = indexPath;
//
// [tableView reloadRowsAtIndexPaths:array withRowAnimation: UITableViewRowAnimationNone];
//}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end