-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
SwitchTableViewCell.m
50 lines (38 loc) · 1.1 KB
/
SwitchTableViewCell.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
//
// SwitchTableViewCell.m
// Strongbox
//
// Created by Strongbox on 01/06/2020.
// Copyright © 2014-2021 Mark McGuill. All rights reserved.
//
#import "SwitchTableViewCell.h"
@interface SwitchTableViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *labelText;
@property (weak, nonatomic) IBOutlet UISwitch *switchOnOff;
@property (nonatomic, copy) void (^onChanged)(BOOL);
@end
@implementation SwitchTableViewCell
- (void)prepareForReuse {
[super prepareForReuse];
self.switchOnOff.on = NO;
self.labelText.text = @"";
self.onChanged = nil;
}
- (void)set:(NSString *)text on:(BOOL)on onChanged:(void (^)(BOOL))onChanged {
[self set:text on:on enabled:YES onChanged:onChanged];
}
- (void)set:(NSString *)text on:(BOOL)on enabled:(BOOL)enabled onChanged:(void (^)(BOOL))onChanged {
self.labelText.text = text;
self.switchOnOff.on = on;
self.switchOnOff.enabled = enabled;
self.onChanged = onChanged;
}
- (BOOL)on {
return self.switchOnOff.on;
}
- (IBAction)onSwitchOnOff:(id)sender {
if (self.onChanged) {
self.onChanged(self.on);
}
}
@end