-
Notifications
You must be signed in to change notification settings - Fork 0
/
AADictionaryViewController.m
82 lines (57 loc) · 2.34 KB
/
AADictionaryViewController.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
//
// AADictionaryViewController.m
// AADictionaryViewController
//
// Created by Aaron Ash on 5/3/15.
//
//
#import "AADictionaryViewController.h"
@interface AADictionaryViewController ()
@end
@implementation AADictionaryViewController
- (id)initWithDictionary:(NSDictionary*)dict {
self = [super initWithStyle:UITableViewStylePlain];
if (self) {
self.dictionary = dict;
}
return self;
}
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:animated];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.clearsSelectionOnViewWillAppear = NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return self.dictionary.allKeys.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
}
cell.textLabel.text = [self.dictionary.allKeys objectAtIndex:indexPath.row];
NSString *formatted = [NSString stringWithFormat:@"%@", [self.dictionary valueForKey:[self.dictionary.allKeys objectAtIndex:indexPath.row]]];
NSString *detail = [[formatted componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@" "];
cell.detailTextLabel.text = detail;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSObject *object = [self.dictionary valueForKey:[self.dictionary.allKeys objectAtIndex:indexPath.row]];
if ([object isKindOfClass:[NSDictionary class]]) {
AADictionaryViewController *vc = [[AADictionaryViewController alloc] initWithDictionary:(NSDictionary*)object];
[self.navigationController pushViewController:vc animated:true];
}
}
@end