/
SPSourceTVC.m
84 lines (63 loc) · 2.25 KB
/
SPSourceTVC.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
//
// SPSourceTVC.m
// SpyPhone
//
// Created by Nicolas Seriot on 11/17/09.
// Copyright 2009. All rights reserved.
// Licensed under GPL 2.0 http://www.gnu.org/licenses/gpl-2.0.txt
//
#import "SPSourceTVC.h"
#import "SPCell.h"
@implementation SPSourceTVC
@synthesize contentsDictionaries;
- (UIImage *)image {
NSString *className = NSStringFromClass([self class]);
NSString *name = nil;
if([className hasPrefix:@"SPSource"] && [className hasSuffix:@"TVC"]) {
NSRange range = NSMakeRange(8, [className length] - 3 - 8);
name = [className substringWithRange:range];
}
NSString *imageName = [name stringByAppendingPathExtension:@"png"];
return [UIImage imageNamed:imageName];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)loadData {
// to be overriden by subclasses
}
- (void)viewDidLoad {
[super viewDidLoad];
if(!contentsDictionaries) [self loadData];
}
- (void)dealloc {
[super dealloc];
}
#pragma mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [contentsDictionaries count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSDictionary *d = [contentsDictionaries objectAtIndex:section];
return [[d allKeys] lastObject];
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
NSDictionary *d = [contentsDictionaries objectAtIndex:section];
NSArray *a = [[d allValues] lastObject];
return [a count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SourceCellIdentifier = @"SPCell";
SPCell *cell = (SPCell *)[tableView dequeueReusableCellWithIdentifier:SourceCellIdentifier];
if (cell == nil) {
cell = (SPCell *)[[[NSBundle mainBundle] loadNibNamed:@"SPCell" owner:self options:nil] lastObject];
}
NSArray *a = [[[contentsDictionaries objectAtIndex:indexPath.section] allValues] lastObject];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.textLabel.text = [a objectAtIndex:indexPath.row];
return cell;
}
@end