SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
iOS/GBOptionViewController.m
1 #import "GBOptionViewController.h"
2
3 @implementation GBOptionViewController
4 {
5 NSMutableArray<NSString *> *_options;
6 NSMutableArray<void (^)(void)> *_actions;
7 NSMutableArray<NSNumber *> *_checked;
8 }
9
10 - (instancetype)initWithHeader:(NSString *)header
11 {
12 UITableViewStyle style = UITableViewStyleGrouped;
13 if (@available(iOS 13.0, *)) {
14 style = UITableViewStyleInsetGrouped;
15 }
16 self = [super initWithStyle:style];
17 self.header = header;
18 _options = [NSMutableArray array];
19 _actions = [NSMutableArray array];
20 _checked = [NSMutableArray array];
21 return self;
22 }
23
24 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
25 {
26 return self.header;
27 }
28
29 - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
30 {
31 return self.footer;
32 }
33
34 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
35 {
36 return 1;
37 }
38
39 - (NSInteger)tableView:(UITableView *)tableView
40 numberOfRowsInSection:(NSInteger)section
41 {
42 return _options.count;
43 }
44
45 - (void)addOption:(NSString *)title
46 withCheckmark:(bool)checked
47 action:(void (^)(void))block
48 {
49 [_options addObject:title];
50 [_actions addObject:block];
51 [_checked addObject:@(checked)];
52 }
53
54 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
55 {
56 UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
57 cell.textLabel.text = _options[[indexPath indexAtPosition:1]];
58 cell.accessoryType = _checked[[indexPath indexAtPosition:1]].boolValue? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
59
60 return cell;
61 }
62
63 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
64 {
65 [self.presentingViewController dismissViewControllerAnimated:true completion:^{
66 _actions[[indexPath indexAtPosition:1]]();
67 }];
68 }
69
70 - (BOOL)isModalInPresentation
71 {
72 return self.isModal;
73 }
74 @end
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.