-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreditsKit.m
105 lines (75 loc) · 3.48 KB
/
CreditsKit.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#import "CreditsKit.h"
#import "CreditsKitDetail.h"
@interface CreditsKit ()
@property NSArray *credits;
@end
@implementation CreditsKit
-(id) initWithPListFile:(NSString *)fileName{
self = [super init];
if (self) {
NSString *PlistPath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"plist"];
NSMutableArray *dict = [[NSMutableArray alloc] initWithContentsOfFile:PlistPath];
self.credits = [dict copy];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style: UIBarButtonItemStyleBordered target:self action:@selector(doneButtonPressed:)];
self.navigationItem.rightBarButtonItem = backButton;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.estimatedRowHeight = 80;//the estimatedRowHeight but if is more this autoincremented with autolayout
self.tableView.rowHeight = UITableViewAutomaticDimension;
[self.tableView setNeedsLayout];
[self.tableView layoutIfNeeded];
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0) ;
}
- (void) doneButtonPressed:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (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 [self.credits count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString* header = [self.credits objectAtIndex:indexPath.row][@"Title"];
NSString* description = [self.credits objectAtIndex:indexPath.row][@"Text"];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = header;
cell.detailTextLabel.text = description;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString* header = [self.credits objectAtIndex:indexPath.row][@"Title"];
NSString* description = [self.credits objectAtIndex:indexPath.row][@"Text"];
UIAlertView *messageAlert = [[UIAlertView alloc]
initWithTitle:header message:description delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
messageAlert.width = self.tableView.width;
// Display Alert Message
//[messageAlert show];
[self showDetailFor:header description:description];
}
-(void) showDetailFor:(NSString*) title description:(NSString*) description {
// Create the PlainViewController (and give it a title)
CreditsKitDetail * vc = [[CreditsKitDetail alloc] initWithContentTitle:title description:description];
[vc setTitle:title];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
nav.navigationBar.barTintColor = kSummaryColor;
nav.navigationBar.translucent = NO;
[self presentViewController:nav animated:YES completion:nil];
}
@end