-
Notifications
You must be signed in to change notification settings - Fork 1
/
SSDropDown.m
557 lines (504 loc) · 23.2 KB
/
SSDropDown.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
//
// SSDropDown.m
//
//
// Created by Shebin Koshy on 4/13/16.
// Copyright © 2016 Shebin Koshy. All rights reserved.
//
#import "SSDropDown.h"
#define kDefaultSSDropDownViewColor [UIColor colorWithWhite:0.4 alpha:1.0]
#define kDefaultSSDropDownHeight 80.0f
#define kDefaultFontSize 13.0f
#define kDefaultSSDropDownTableViewCellHeight 40.0f
#define kDefaultGapBetweenSSDropDownAndViewForDropDown 0.5f
#define kDefaultArrowWidth 8.0f
#define kDefaultAnimationDuration 0.3
#define kCellIdentifier @"CellIdentifier"
//#define kCoveringViewColor [UIColor colorWithWhite:0.7 alpha:0.5]
#define kCoveringViewColor [UIColor clearColor]
@interface SSDropDown ()<UITableViewDataSource,UITableViewDelegate,UIGestureRecognizerDelegate>
{
CAShapeLayer *shapeLayer;
CAShapeLayer *shapeArrow;
id selectedItem;
UIView *viewBackground;
UIView *viewToShowDropDown;
UIView *superViewToShowDropDown;
}
@end
@implementation SSDropDown
-(instancetype)init
{
if(self == [super init])
{
self.tableViewDropDownList = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
self.tableViewDropDownList.delegate = self;
self.tableViewDropDownList.dataSource = self;
self.tableViewDropDownList.tableFooterView = [[UIView alloc] init];
return self;
}
return nil;
}
-(void)showDropDownForView:(UIView*)viewForDropDown insideTheCell:(nonnull id)cell withSelectedObject:(nullable id)selectedObject
{
selectedItem = selectedObject;
UIView *superView;
if([cell isKindOfClass:[UITableViewCell class]])
{
UITableViewCell *tableCell = cell;
superView = tableCell.contentView;
}
else if ([cell isKindOfClass:[UICollectionViewCell class]])
{
UICollectionViewCell *collectionCell = cell;
superView = collectionCell.contentView;
}
[self showDropDownForView:viewForDropDown insideTheView:superView animation:_needAnimation];
}
-(void)showDropDownForView:(UIView *)viewForDropDown withSelectedObject:(id)selectedObject
{
selectedItem = selectedObject;
[self showDropDownForView:viewForDropDown insideTheView:viewForDropDown.superview animation:_needAnimation];
}
-(void)showDropDownForView:(UIView *)viewForDropDown insideTheView:(UIView *)superView animation:(BOOL)animate
{
viewToShowDropDown = viewForDropDown;
superViewToShowDropDown = superView;
if (_needCustomCell)
{
[self.delegate dropDown:self registerCustomCellForTheDropDownTableView:self.tableViewDropDownList];
}
else
{
[self.tableViewDropDownList registerClass:[UITableViewCell class] forCellReuseIdentifier:kCellIdentifier];
}
if (!self.dropDownHeight || self.dropDownHeight == 0.0f)
{
/**
if its null or zero,
setting default value.
*/
self.dropDownHeight = kDefaultSSDropDownHeight;
}
if (!self.dropDownWidth || self.dropDownWidth == 0.0f)
{
self.dropDownWidth = viewForDropDown.frame.size.width;
}
self.backgroundColor = _dropDownBackgroundColor;
if (!self.backgroundColor || [self.backgroundColor isEqual:[UIColor clearColor]])
{
self.backgroundColor = kDefaultSSDropDownViewColor;
}
viewBackground = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
[viewBackground setBackgroundColor:kCoveringViewColor];
if (_navigationController)
{
[_navigationController.view addSubview:viewBackground];
}
else if([UIApplication sharedApplication].keyWindow.rootViewController)
{
[[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:viewBackground];
}
else
{
id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.window.rootViewController.view addSubview:viewBackground];
}
CGPoint point = [superView convertPoint:viewForDropDown.frame.origin toView:viewBackground];
if (self.dropDownPosition == kSSDropDownPositionBottom)
{
[self setFrame:CGRectMake(point.x - ((self.dropDownWidth - viewForDropDown.frame.size.width)/2), point.y + viewForDropDown.frame.size.height, self.dropDownWidth, self.dropDownHeight)];
}
else if (self.dropDownPosition == kSSDropDownPositionTop)
{
[self setFrame:CGRectMake(point.x - ((self.dropDownWidth - viewForDropDown.frame.size.width)/2), point.y - self.dropDownHeight, self.dropDownWidth, self.dropDownHeight)];
}
else if (self.dropDownPosition == kSSDropDownPositionLeft)
{
[self setFrame:CGRectMake(point.x - self.dropDownWidth, (point.y+(viewForDropDown.frame.size.height)/2) - (self.dropDownHeight/2), self.dropDownWidth, self.dropDownHeight)];
}
else if (self.dropDownPosition == kSSDropDownPositionRight)
{
[self setFrame:CGRectMake(point.x + viewForDropDown.frame.size.width, (point.y+(viewForDropDown.frame.size.height)/2) - (self.dropDownHeight/2), self.dropDownWidth, self.dropDownHeight)];
}
[self.tableViewDropDownList setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
[self creatShape];
[self.tableViewDropDownList setBackgroundColor:self.backgroundColor];
[self.tableViewDropDownList reloadData];
[self addSubview:self.tableViewDropDownList];
[viewBackground addSubview:self];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureAction:)];
tapGesture.delegate = self;
[viewBackground addGestureRecognizer:tapGesture];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceRotated) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
if (animate)
{
[self showingAnimation];
}
}
-(void)deviceRotated
{
dispatch_async(dispatch_get_main_queue(), ^{
[self needToDoOnRemove];
if ([self.delegate respondsToSelector:@selector(dropDown:orientationChanged:)])
{
[self.delegate dropDown:self orientationChanged:UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)];
}
[self showDropDownForView:viewToShowDropDown insideTheView:superViewToShowDropDown animation:NO];
});
}
-(void)showingAnimation
{
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
UIColor *colorOld = viewBackground.backgroundColor;
viewBackground.backgroundColor = [UIColor clearColor];
// [self setAlpha:0.0f];
// [viewBackground setAlpha:0.0f];
CGRect frameOld = self.frame;
self.clipsToBounds = YES;
if (self.dropDownPosition == kSSDropDownPositionBottom)
{
self.frame = CGRectMake(frameOld.origin.x, frameOld.origin.y, frameOld.size.width, 0);
}
else if (self.dropDownPosition == kSSDropDownPositionTop)
{
self.frame = CGRectMake(frameOld.origin.x, frameOld.origin.y + frameOld.size.height, frameOld.size.width, 0);
}
else if (self.dropDownPosition == kSSDropDownPositionLeft)
{
self.frame = CGRectMake(frameOld.origin.x + frameOld.size.width, frameOld.origin.y,0, frameOld.size.height);
}
else if (self.dropDownPosition == kSSDropDownPositionRight)
{
self.frame = CGRectMake(frameOld.origin.x, frameOld.origin.y, 0, frameOld.size.height);
}
[UIView animateWithDuration:kDefaultAnimationDuration animations:^{
// [self setAlpha:1.0f];
// [viewBackground setAlpha:1.0f];
self.frame = frameOld;
viewBackground.backgroundColor = colorOld;
}completion:^(BOOL finished) {
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
[self setClipsToBounds:NO];
}];
}
-(void)tapGestureAction:(UITapGestureRecognizer*)tapGesture
{
[tapGesture setCancelsTouchesInView:NO];
CGPoint point = [tapGesture locationInView:tapGesture.view];
if (CGRectContainsPoint(self.frame, point) == NO)
{
[self removeDropDown];
}
}
-(void)creatShape
{
/**
Removing the previous changes
*/
if (shapeLayer)
{
[shapeLayer removeFromSuperlayer];
}
if (shapeArrow)
{
[shapeArrow removeFromSuperlayer];
}
self.layer.cornerRadius = 0.0;
self.tableViewDropDownList.layer.cornerRadius = 0.0;
if (_needToShowArrow)
{
CGFloat static arrowWidth = kDefaultArrowWidth;
/**
if need to show arrow, then dropDownView frame will change.
so, calculating tableView frame
*/
CGRect frameTable = CGRectZero;
if (self.dropDownPosition == kSSDropDownPositionLeft)
{
frameTable = CGRectMake(0, 0, self.dropDownWidth - arrowWidth, self.dropDownHeight);
}
else if (self.dropDownPosition == kSSDropDownPositionBottom)
{
frameTable = CGRectMake(0, arrowWidth, self.dropDownWidth, self.dropDownHeight - arrowWidth);
}
else if (self.dropDownPosition == kSSDropDownPositionTop)
{
frameTable = CGRectMake(0, 0, self.dropDownWidth, self.dropDownHeight - arrowWidth);
}
else if (self.dropDownPosition == kSSDropDownPositionRight)
{
frameTable = CGRectMake(arrowWidth, 0, self.dropDownWidth - arrowWidth, self.dropDownHeight);
}
[self.tableViewDropDownList setFrame:frameTable];
if (_cornerRadius)
{
/**
need to show Arrow and CornerRadius
*/
shapeLayer = [CAShapeLayer layer];
shapeArrow = [CAShapeLayer layer];
if (self.dropDownPosition == kSSDropDownPositionLeft)
{
UIBezierPath *pathRoundRect = [UIBezierPath bezierPathWithRoundedRect:frameTable cornerRadius:_cornerRadius];
shapeLayer.path = pathRoundRect.CGPath;
UIBezierPath *pathArrow = [UIBezierPath bezierPath];
[pathArrow moveToPoint:CGPointMake(self.dropDownWidth - arrowWidth, self.dropDownHeight/2 - arrowWidth)];
[pathArrow addLineToPoint:CGPointMake(self.dropDownWidth, self.dropDownHeight/2)];
[pathArrow addLineToPoint:CGPointMake(self.dropDownWidth - arrowWidth, self.dropDownHeight/2 + arrowWidth)];
[pathArrow closePath];
shapeArrow.path = pathArrow.CGPath;
}
else if (self.dropDownPosition == kSSDropDownPositionBottom)
{
UIBezierPath *pathRoundRect = [UIBezierPath bezierPathWithRoundedRect:frameTable cornerRadius:_cornerRadius];
shapeLayer.path = pathRoundRect.CGPath;
UIBezierPath *pathArrow = [UIBezierPath bezierPath];
[pathArrow moveToPoint:CGPointMake(self.dropDownWidth/2 - arrowWidth, arrowWidth)];
[pathArrow addLineToPoint:CGPointMake(self.dropDownWidth/2, 0)];
[pathArrow addLineToPoint:CGPointMake(self.dropDownWidth/2 + arrowWidth, arrowWidth)];
[pathArrow closePath];
shapeArrow.path = pathArrow.CGPath;
}
else if (self.dropDownPosition == kSSDropDownPositionTop)
{
UIBezierPath *pathRoundRect = [UIBezierPath bezierPathWithRoundedRect:frameTable cornerRadius:_cornerRadius];
shapeLayer.path = pathRoundRect.CGPath;
UIBezierPath *pathArrow = [UIBezierPath bezierPath];
[pathArrow moveToPoint:CGPointMake((self.dropDownWidth/2) - arrowWidth, self.dropDownHeight - arrowWidth)];
[pathArrow addLineToPoint:CGPointMake((self.dropDownWidth/2), self.dropDownHeight)];
[pathArrow addLineToPoint:CGPointMake((self.dropDownWidth/2) + arrowWidth, self.dropDownHeight - arrowWidth)];
[pathArrow closePath];
shapeArrow.path = pathArrow.CGPath;
}
else if (self.dropDownPosition == kSSDropDownPositionRight)
{
UIBezierPath *pathRoundRect = [UIBezierPath bezierPathWithRoundedRect:frameTable cornerRadius:_cornerRadius];
shapeLayer.path = pathRoundRect.CGPath;
UIBezierPath *pathArrow = [UIBezierPath bezierPath];
[pathArrow moveToPoint:CGPointMake(arrowWidth, (self.dropDownHeight/2) - arrowWidth)];
[pathArrow addLineToPoint:CGPointMake(0, self.dropDownHeight/2)];
[pathArrow addLineToPoint:CGPointMake(arrowWidth, (self.dropDownHeight/2) + arrowWidth)];
[pathArrow closePath];
shapeArrow.path = pathArrow.CGPath;
}
shapeLayer.fillColor = self.backgroundColor.CGColor;
[self.layer addSublayer:shapeLayer];
shapeArrow.fillColor = self.backgroundColor.CGColor;
[self.layer addSublayer:shapeArrow];
[self.tableViewDropDownList.layer setCornerRadius:_cornerRadius];
[self setClipsToBounds:YES];
[self.tableViewDropDownList setClipsToBounds:YES];
}
else
{
/**
need to show Arrow WITHOUT CornerRadius
*/
UIBezierPath *path = [UIBezierPath bezierPath];
if (self.dropDownPosition == kSSDropDownPositionLeft)
{
[path moveToPoint:CGPointZero];
[path addLineToPoint:CGPointMake(self.dropDownWidth - arrowWidth, 0)];
[path addLineToPoint:CGPointMake(self.dropDownWidth - arrowWidth, (self.dropDownHeight/2)-arrowWidth)];
[path addLineToPoint:CGPointMake(self.dropDownWidth, self.dropDownHeight/2)];
[path addLineToPoint:CGPointMake(self.dropDownWidth - arrowWidth, (self.dropDownHeight/2)+arrowWidth)];
[path addLineToPoint:CGPointMake(self.dropDownWidth - arrowWidth, self.dropDownHeight)];
[path addLineToPoint:CGPointMake(0, self.dropDownHeight)];
}
else if (self.dropDownPosition == kSSDropDownPositionBottom)
{
[path moveToPoint:CGPointMake(0, arrowWidth)];
[path addLineToPoint:CGPointMake((self.dropDownWidth/2) - arrowWidth, arrowWidth)];
[path addLineToPoint:CGPointMake(self.dropDownWidth/2, 0)];
[path addLineToPoint:CGPointMake(self.dropDownWidth/2 + arrowWidth, arrowWidth)];
[path addLineToPoint:CGPointMake(self.dropDownWidth, arrowWidth)];
[path addLineToPoint:CGPointMake(self.dropDownWidth, self.dropDownHeight)];
[path addLineToPoint:CGPointMake(0, self.dropDownHeight)];
}
else if (self.dropDownPosition == kSSDropDownPositionTop)
{
[path moveToPoint:CGPointZero];
[path addLineToPoint:CGPointMake(self.dropDownWidth, 0.0)];
[path addLineToPoint:CGPointMake(self.dropDownWidth, self.dropDownHeight - arrowWidth)];
[path addLineToPoint:CGPointMake((self.dropDownWidth/2) + arrowWidth, self.dropDownHeight - arrowWidth)];
[path addLineToPoint:CGPointMake(self.dropDownWidth/2, self.dropDownHeight)];
[path addLineToPoint:CGPointMake(self.dropDownWidth/2 - arrowWidth, self.dropDownHeight - arrowWidth)];
[path addLineToPoint:CGPointMake(0, self.dropDownHeight - arrowWidth)];
}
else if (self.dropDownPosition == kSSDropDownPositionRight)
{
[path moveToPoint:CGPointMake(arrowWidth, 0)];
[path addLineToPoint:CGPointMake(self.dropDownWidth/* - arrowWidth*/, 0)];
[path addLineToPoint:CGPointMake(self.dropDownWidth/* - arrowWidth*/, self.dropDownHeight)];
[path addLineToPoint:CGPointMake(arrowWidth, self.dropDownHeight)];
[path addLineToPoint:CGPointMake(arrowWidth, (self.dropDownHeight/2) + arrowWidth)];
[path addLineToPoint:CGPointMake(0, self.dropDownHeight/2)];
[path addLineToPoint:CGPointMake(arrowWidth, (self.dropDownHeight/2) - arrowWidth)];
}
[path closePath];
shapeLayer = [CAShapeLayer layer];
shapeLayer.path = path.CGPath;
shapeLayer.fillColor = self.backgroundColor.CGColor;
[self.layer addSublayer:shapeLayer];
}
self.backgroundColor = [UIColor clearColor];
}
else
{
/**
No Arrow
*/
if(_cornerRadius)
{
[self.layer setCornerRadius:_cornerRadius];
[self setClipsToBounds:YES];
[self.tableViewDropDownList.layer setCornerRadius:_cornerRadius];
[self.tableViewDropDownList setClipsToBounds:YES];
}
if (self.dropDownPosition == kSSDropDownPositionLeft)
{
[self setFrame:CGRectMake(self.frame.origin.x - kDefaultGapBetweenSSDropDownAndViewForDropDown, self.frame.origin.y, self.frame.size.width, self.frame.size.height)];
}
else if (self.dropDownPosition == kSSDropDownPositionBottom)
{
if (_SPECIALCASEBottomCornerRadius)
{
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(_SPECIALCASEBottomCornerRadius, _SPECIALCASEBottomCornerRadius)];
shapeLayer = [CAShapeLayer layer];
shapeLayer.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
shapeLayer.path = bezierPath.CGPath;
shapeLayer.fillColor = self.backgroundColor.CGColor;
self.backgroundColor = [UIColor clearColor];
[self.layer addSublayer:shapeLayer];
self.tableViewDropDownList.frame = CGRectMake(self.tableViewDropDownList.frame.origin.x, self.tableViewDropDownList.frame.origin.y, self.tableViewDropDownList.frame.size.width, self.tableViewDropDownList.frame.size.height - _SPECIALCASEBottomCornerRadius);
}
else
{
[self setFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y + kDefaultGapBetweenSSDropDownAndViewForDropDown, self.frame.size.width, self.frame.size.height)];
}
}
else if (self.dropDownPosition == kSSDropDownPositionTop)
{
[self setFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y - kDefaultGapBetweenSSDropDownAndViewForDropDown, self.frame.size.width, self.frame.size.height)];
}
else if (self.dropDownPosition == kSSDropDownPositionRight)
{
[self setFrame:CGRectMake(self.frame.origin.x + kDefaultGapBetweenSSDropDownAndViewForDropDown, self.frame.origin.y, self.frame.size.width, self.frame.size.height)];
}
}
}
-(void)removeDropDown
{
if (_needAnimation)
{
[self dismissingAnimation];
}
else
{
[self needToDoOnRemove];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
}
}
-(void)needToDoOnRemove
{
[viewBackground removeFromSuperview];
[self removeFromSuperview];
}
-(void)dismissingAnimation
{
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
UIColor *colorOld = viewBackground.backgroundColor;
CGRect frameOld = self.frame;
[UIView animateWithDuration:kDefaultAnimationDuration animations:^{
// [self setAlpha:1.0f];
// [viewBackground setAlpha:1.0f];
self.clipsToBounds = YES;
viewBackground.backgroundColor = [UIColor clearColor];
if (self.dropDownPosition == kSSDropDownPositionBottom)
{
self.frame = CGRectMake(frameOld.origin.x, frameOld.origin.y, frameOld.size.width, 0);
}
else if (self.dropDownPosition == kSSDropDownPositionTop)
{
self.frame = CGRectMake(frameOld.origin.x, frameOld.origin.y + frameOld.size.height, frameOld.size.width, 0);
}
else if (self.dropDownPosition == kSSDropDownPositionLeft)
{
self.frame = CGRectMake(frameOld.origin.x + frameOld.size.width, frameOld.origin.y,0, frameOld.size.height);
}
else if (self.dropDownPosition == kSSDropDownPositionRight)
{
self.frame = CGRectMake(frameOld.origin.x, frameOld.origin.y, 0, frameOld.size.height);
}
}completion:^(BOOL finished) {
self.frame = frameOld;
viewBackground.backgroundColor = colorOld;
[self setClipsToBounds:NO];
[self needToDoOnRemove];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}];
}
#pragma mark - TableView Data Source and Delegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _arrayItemsToList.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if (_needCustomCell)
{
cell = [self.delegate dropDown:self dropDownTableView:tableView cellForRowAtIndexPath:indexPath andSelectedItem:selectedItem];
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
cell.textLabel.text = [_arrayItemsToList objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:kDefaultFontSize];
if (selectedItem && [selectedItem isEqual:[_arrayItemsToList objectAtIndex:indexPath.row]])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
cell.backgroundColor = self.backgroundColor;
cell.contentView.backgroundColor = self.backgroundColor;
}
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.delegate dropDown:self selectedAnObject:[_arrayItemsToList objectAtIndex:indexPath.row] dropDownForTheView:viewToShowDropDown];
[self removeDropDown];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (_needCustomCell && [self.delegate respondsToSelector:@selector(dropDownTableView: heightForRowAtIndexPath:)])
{
return [self.delegate dropDownTableView:tableView heightForRowAtIndexPath:indexPath];
}
else
{
return kDefaultSSDropDownTableViewCellHeight;
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Remove seperator inset
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
// Prevent the cell from inheriting the Table View's margin settings
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}
// Explictly set your cell's layout margins
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
@end