-
-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathMFSVersionPickerViewController.m
More file actions
72 lines (61 loc) · 2.12 KB
/
Copy pathMFSVersionPickerViewController.m
File metadata and controls
72 lines (61 loc) · 2.12 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
#import "MFSVersionPickerViewController.h"
@interface MFSVersionPickerViewController ()
@property (nonatomic, strong) NSArray* versions;
@end
@implementation MFSVersionPickerViewController
- (instancetype)initWithVersions:(NSArray*)versions completion:(MFSVersionPickerCompletion)completion
{
self = [super initWithStyle:UITableViewStyleInsetGrouped];
if (self)
{
_versions = versions;
_completionHandler = completion;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Select Version";
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"VersionCell"];
UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelTapped)];
self.navigationItem.leftBarButtonItem = cancelButton;
}
- (void)cancelTapped
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return self.versions.count;
}
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"VersionCell" forIndexPath:indexPath];
NSDictionary* version = self.versions[indexPath.row];
cell.textLabel.text = version[@"bundle_version"];
cell.textLabel.font = [UIFont monospacedDigitSystemFontOfSize:15 weight:UIFontWeightRegular];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSDictionary* selected = self.versions[indexPath.row];
[self dismissViewControllerAnimated:YES completion:^
{
if (self.completionHandler)
{
self.completionHandler(selected);
}
}];
}
- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section
{
return [NSString stringWithFormat:@"%lu versions available", (unsigned long)self.versions.count];
}
@end