forked from romaonthego/RETableViewManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlsViewController.m
More file actions
326 lines (271 loc) · 14.1 KB
/
Copy pathControlsViewController.m
File metadata and controls
326 lines (271 loc) · 14.1 KB
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
//
// ControlsViewController.m
// RETableViewManagerExample
//
// Created by Roman Efimov on 2/28/13.
// Copyright (c) 2013 Roman Efimov. All rights reserved.
//
#import "ControlsViewController.h"
#import "MultilineTextItem.h"
@interface ControlsViewController ()
@property (strong, readwrite, nonatomic) RETableViewManager *manager;
@property (strong, readwrite, nonatomic) RETableViewSection *basicControlsSection;
@property (strong, readwrite, nonatomic) RETableViewSection *creditCardSection;
@property (strong, readwrite, nonatomic) RETableViewSection *accessoriesSection;
@property (strong, readwrite, nonatomic) RETableViewSection *cutCopyPasteSection;
@property (strong, readwrite, nonatomic) RETableViewSection *buttonSection;
@property (strong, readwrite, nonatomic) RETextItem *fullLengthFieldItem;
@property (strong, readwrite, nonatomic) RETextItem *textItem;
@property (strong, readwrite, nonatomic) RENumberItem *numberItem;
@property (strong, readwrite, nonatomic) RETextItem *passwordItem;
@property (strong, readwrite, nonatomic) REBoolItem *boolItem;
@property (strong, readwrite, nonatomic) REFloatItem *floatItem;
@property (strong, readwrite, nonatomic) REDateTimeItem *dateTimeItem;
@property (strong, readwrite, nonatomic) RERadioItem *radioItem;
@property (strong, readwrite, nonatomic) REMultipleChoiceItem *multipleChoiceItem;
@property (strong, readwrite, nonatomic) RELongTextItem *longTextItem;
@property (strong, readwrite, nonatomic) RECreditCardItem *creditCardItem;
@property (strong, readwrite, nonatomic) RECreditCardItem *creditCardItemCVV;
@property (strong, readwrite, nonatomic) REPickerItem *pickerItem;
@property (strong, readwrite, nonatomic) RESegmentedItem *segmentItem;
@property (strong, readwrite, nonatomic) RESegmentedItem *segmentItem2;
@end
@implementation ControlsViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Controls";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Values" style:UIBarButtonItemStyleBordered target:self action:@selector(valuesButtonPressed:)];
// Create manager
//
self.manager = [[RETableViewManager alloc] initWithTableView:self.tableView delegate:self];
self.basicControlsSection = [self addBasicControls];
self.creditCardSection = [self addCreditCard];
self.accessoriesSection = [self addAccessories];
self.cutCopyPasteSection = [self addCutCopyPaste];
self.buttonSection = [self addButton];
}
- (void)valuesButtonPressed:(id)sender
{
NSLog(@"fullLengthFieldItem.value = %@", self.fullLengthFieldItem.value);
NSLog(@"textItem.value = %@", self.textItem.value);
NSLog(@"numberItem.value = %@", self.numberItem.value);
NSLog(@"passwordItem.value = %@", self.passwordItem.value);
NSLog(@"boolItem.value = %@", self.boolItem.value ? @"YES" : @"NO");
NSLog(@"floatItem.value = %f", self.floatItem.value);
NSLog(@"dateTimeItem = %@", self.dateTimeItem.value);
NSLog(@"radioItem.value = %@", self.radioItem.value);
NSLog(@"multipleChoiceItem.value = %@", self.multipleChoiceItem.value);
NSLog(@"longTextItem.value = %@", self.longTextItem.value);
NSLog(@"creditCardItem.number = %@, creditCardItem.expirationDate = %@, creditCardItem.cvv = %@", self.creditCardItem.number, self.creditCardItem.expirationDate, self.creditCardItem.cvv);
}
#pragma mark -
#pragma mark Basic Controls Example
- (RETableViewSection *)addBasicControls
{
__typeof (&*self) __weak weakSelf = self;
RETableViewSection *section = [RETableViewSection sectionWithHeaderTitle:@"Basic controls"];
[self.manager addSection:section];
// Custom item / cell
self.manager[@"MultilineTextItem"] = @"MultilineTextCell";
// Add items to this section
//
[section addItem:@"Simple NSString"];
self.fullLengthFieldItem = [RETextItem itemWithTitle:nil value:nil placeholder:@"Full length text field"];
self.textItem = [RETextItem itemWithTitle:@"Text item" value:nil placeholder:@"Text"];
self.numberItem = [RENumberItem itemWithTitle:@"Phone" value:@"" placeholder:@"(123) 456-7890" format:@"(XXX) XXX-XXXX"];
self.numberItem.onEndEditing = ^(RENumberItem *item){
NSLog(@"Value: %@", item.value);
};
self.passwordItem = [RETextItem itemWithTitle:@"Password" value:nil placeholder:@"Password item"];
self.passwordItem.secureTextEntry = YES;
self.boolItem = [REBoolItem itemWithTitle:@"Bool item" value:YES switchValueChangeHandler:^(REBoolItem *item) {
NSLog(@"Value: %@", item.value ? @"YES" : @"NO");
}];
self.segmentItem = [RESegmentedItem itemWithTitle:@"Segmented" segmentedControlTitles:@[@"One", @"Two"] value:1 switchValueChangeHandler:^(RESegmentedItem *item) {
NSLog(@"Value: %i", item.value);
}];
self.segmentItem2 = [RESegmentedItem itemWithTitle:nil segmentedControlImages:@[[UIImage imageNamed:@"Heart"], [UIImage imageNamed:@"Heart_Highlighted"]] value:0 switchValueChangeHandler:^(RESegmentedItem *item) {
NSLog(@"Value: %i", item.value);
}];
self.segmentItem2.tintColor = [UIColor orangeColor];
self.floatItem = [REFloatItem itemWithTitle:@"Float item" value:0.3 sliderValueChangeHandler:^(REFloatItem *item) {
NSLog(@"Value: %f", item.value);
}];
self.dateTimeItem = [REDateTimeItem itemWithTitle:@"Date / Time" value:[NSDate date] placeholder:nil format:@"MM/dd/yyyy hh:mm a" datePickerMode:UIDatePickerModeDateAndTime];
self.dateTimeItem.onChange = ^(REDateTimeItem *item){
NSLog(@"Value: %@", item.value.description);
};
// Use inline date picker in iOS 7
//
if (REUIKitIsFlatMode()) {
self.dateTimeItem.inlineDatePicker = YES;
}
self.pickerItem = [REPickerItem itemWithTitle:@"Picker" value:@[@"Item 12", @"Item 23"] placeholder:nil options:@[@[@"Item 11", @"Item 12", @"Item 13"], @[@"Item 21", @"Item 22", @"Item 23", @"Item 24"]]];
self.pickerItem.onChange = ^(REPickerItem *item){
NSLog(@"Value: %@", item.value);
};
// Use inline picker in iOS 7
//
if (REUIKitIsFlatMode()) {
self.pickerItem.inlinePicker = YES;
}
self.radioItem = [RERadioItem itemWithTitle:@"Radio" value:@"Option 4" selectionHandler:^(RERadioItem *item) {
[item deselectRowAnimated:YES]; // same as [weakSelf.tableView deselectRowAtIndexPath:item.indexPath animated:YES];
// Generate sample options
//
NSMutableArray *options = [[NSMutableArray alloc] init];
for (NSInteger i = 1; i < 40; i++)
[options addObject:[NSString stringWithFormat:@"Option %li", (long) i]];
// Present options controller
//
RETableViewOptionsController *optionsController = [[RETableViewOptionsController alloc] initWithItem:item options:options multipleChoice:NO completionHandler:^{
[weakSelf.navigationController popViewControllerAnimated:YES];
[item reloadRowWithAnimation:UITableViewRowAnimationNone]; // same as [weakSelf.tableView reloadRowsAtIndexPaths:@[item.indexPath] withRowAnimation:UITableViewRowAnimationNone];
}];
// Adjust styles
//
optionsController.delegate = weakSelf;
optionsController.style = section.style;
if (weakSelf.tableView.backgroundView == nil) {
optionsController.tableView.backgroundColor = weakSelf.tableView.backgroundColor;
optionsController.tableView.backgroundView = nil;
}
// Push the options controller
//
[weakSelf.navigationController pushViewController:optionsController animated:YES];
}];
self.multipleChoiceItem = [REMultipleChoiceItem itemWithTitle:@"Multiple" value:@[@"Option 2", @"Option 4"] selectionHandler:^(REMultipleChoiceItem *item) {
[item deselectRowAnimated:YES];
// Generate sample options
//
NSMutableArray *options = [[NSMutableArray alloc] init];
for (NSInteger i = 1; i < 40; i++)
[options addObject:[NSString stringWithFormat:@"Option %li", (long) i]];
// Present options controller
//
RETableViewOptionsController *optionsController = [[RETableViewOptionsController alloc] initWithItem:item options:options multipleChoice:YES completionHandler:^{
[item reloadRowWithAnimation:UITableViewRowAnimationNone];
NSLog(@"%@", item.value);
}];
// Adjust styles
//
optionsController.delegate = weakSelf;
optionsController.style = section.style;
if (weakSelf.tableView.backgroundView == nil) {
optionsController.tableView.backgroundColor = weakSelf.tableView.backgroundColor;
optionsController.tableView.backgroundView = nil;
}
// Push the options controller
//
[weakSelf.navigationController pushViewController:optionsController animated:YES];
}];
self.longTextItem = [RELongTextItem itemWithValue:nil placeholder:@"Multiline text field"];
self.longTextItem.cellHeight = 88;
[section addItem:self.fullLengthFieldItem];
[section addItem:self.textItem];
[section addItem:self.numberItem];
[section addItem:self.passwordItem];
[section addItem:self.boolItem];
[section addItem:self.floatItem];
[section addItem:self.dateTimeItem];
[section addItem:self.pickerItem];
[section addItem:self.radioItem];
[section addItem:self.multipleChoiceItem];
[section addItem:self.segmentItem];
[section addItem:self.segmentItem2];
[section addItem:self.longTextItem];
[section addItem:[MultilineTextItem itemWithTitle:@"Custom item / cell example. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sem leo, malesuada tempor metus et, elementum pulvinar nibh."]];
RETableViewItem *titleAndImageItem = [RETableViewItem itemWithTitle:@"Text and image item" accessoryType:UITableViewCellAccessoryNone selectionHandler:^(RETableViewItem *item) {
[item deselectRowAnimated:YES];
}];
titleAndImageItem.image = [UIImage imageNamed:@"Heart"];
titleAndImageItem.highlightedImage = [UIImage imageNamed:@"Heart_Highlighted"];
[section addItem:titleAndImageItem];
return section;
}
#pragma mark -
#pragma mark Credit Card Example
- (RETableViewSection *)addCreditCard
{
RETableViewSection *section = [RETableViewSection sectionWithHeaderTitle:@"Credit card"];
[self.manager addSection:section];
self.creditCardItem = [RECreditCardItem item];
[section addItem:self.creditCardItem];
return section;
}
#pragma mark -
#pragma mark Accessories Example
- (RETableViewSection *)addAccessories
{
RETableViewSection *section = [RETableViewSection sectionWithHeaderTitle:@"Accessories"];
[self.manager addSection:section];
// Add items to this section
//
[section addItem:[RETableViewItem itemWithTitle:@"Accessory 1" accessoryType:UITableViewCellAccessoryDisclosureIndicator selectionHandler:^(RETableViewItem *item) {
[item deselectRowAnimated:YES];
}]];
[section addItem:[RETableViewItem itemWithTitle:@"Accessory 2" accessoryType:UITableViewCellAccessoryDetailDisclosureButton selectionHandler:^(RETableViewItem *item) {
[item deselectRowAnimated:YES];
} accessoryButtonTapHandler:^(RETableViewItem *item) {
NSLog(@"Accessory button in accessoryItem2 was tapped");
}]];
[section addItem:[RETableViewItem itemWithTitle:@"Accessory 2" accessoryType:UITableViewCellAccessoryCheckmark selectionHandler:^(RETableViewItem *item) {
[item deselectRowAnimated:YES];
}]];
return section;
}
#pragma mark -
#pragma mark Cut, Copy and Paste Example
- (RETableViewSection *)addCutCopyPaste
{
RETableViewSection *section = [RETableViewSection sectionWithHeaderTitle:@"Copy / pasting"];
[self.manager addSection:section];
RETableViewItem *copyItem = [RETableViewItem itemWithTitle:@"Long tap to copy this item" accessoryType:UITableViewCellAccessoryNone selectionHandler:^(RETableViewItem *item) {
[item deselectRowAnimated:YES];
}];
copyItem.copyHandler = ^(RETableViewItem *item) {
[UIPasteboard generalPasteboard].string = @"Copied item #1";
};
[section addItem:copyItem];
RETableViewItem *pasteItem = [RETableViewItem itemWithTitle:@"Long tap to paste into this item" accessoryType:UITableViewCellAccessoryNone selectionHandler:^(RETableViewItem *item) {
[item deselectRowAnimated:YES];
}];
pasteItem.pasteHandler = ^(RETableViewItem *item) {
item.title = [UIPasteboard generalPasteboard].string;
[item reloadRowWithAnimation:UITableViewRowAnimationAutomatic];
};
[section addItem:pasteItem];
RETableViewItem *cutCopyPasteItem = [RETableViewItem itemWithTitle:@"Long tap to cut / copy / paste" accessoryType:UITableViewCellAccessoryNone selectionHandler:^(RETableViewItem *item) {
[item deselectRowAnimated:YES];
}];
cutCopyPasteItem.copyHandler = ^(RETableViewItem *item) {
[UIPasteboard generalPasteboard].string = @"Copied item #3";
};
cutCopyPasteItem.pasteHandler = ^(RETableViewItem *item) {
item.title = [UIPasteboard generalPasteboard].string;
[item reloadRowWithAnimation:UITableViewRowAnimationAutomatic];
};
cutCopyPasteItem.cutHandler = ^(RETableViewItem *item) {
item.title = @"(Empty)";
[UIPasteboard generalPasteboard].string = @"Copied item #3";
[item reloadRowWithAnimation:UITableViewRowAnimationAutomatic];
};
[section addItem:cutCopyPasteItem];
return section;
}
#pragma mark -
#pragma mark Button Example
- (RETableViewSection *)addButton
{
RETableViewSection *section = [RETableViewSection section];
[self.manager addSection:section];
RETableViewItem *buttonItem = [RETableViewItem itemWithTitle:@"Test button" accessoryType:UITableViewCellAccessoryNone selectionHandler:^(RETableViewItem *item) {
item.title = @"Pressed!";
[item reloadRowWithAnimation:UITableViewRowAnimationAutomatic];
}];
buttonItem.textAlignment = NSTextAlignmentCenter;
[section addItem:buttonItem];
return section;
}
@end