blob: edddbd8f1c210382a225417d4d7d1f758511f86a (
plain)
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
|
#import "MuDocumentController.h"
#import "MuOutlineController.h"
@implementation MuOutlineController
{
MuDocumentController *target;
NSMutableArray *titles;
NSMutableArray *pages;
}
- (instancetype) initWithTarget: (id)aTarget titles: (NSMutableArray*)aTitles pages: (NSMutableArray*)aPages
{
self = [super initWithStyle: UITableViewStylePlain];
if (self) {
[self setTitle: @"Table of Contents"];
target = aTarget; // only keep a weak reference, to avoid retain cycles
titles = [aTitles retain];
pages = [aPages retain];
[[self tableView] setSeparatorStyle: UITableViewCellSeparatorStyleNone];
}
return self;
}
- (void) dealloc
{
[titles release];
[pages release];
[super dealloc];
}
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)o
{
return YES;
}
- (NSInteger) numberOfSectionsInTableView: (UITableView*)tableView
{
return 1;
}
- (NSInteger) tableView: (UITableView*)tableView numberOfRowsInSection: (NSInteger)section
{
return [titles count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 28;
}
- (UITableViewCell*) tableView: (UITableView*)tableView cellForRowAtIndexPath: (NSIndexPath*)indexPath
{
static NSString *cellid = @"MuCellIdent";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellid];
if (!cell)
{
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier: cellid] autorelease];
[[cell textLabel] setFont: [UIFont systemFontOfSize: 16]];
[[cell detailTextLabel] setFont: [UIFont systemFontOfSize: 16]];
}
NSString *title = [titles objectAtIndex: [indexPath row]];
NSString *page = [pages objectAtIndex: [indexPath row]];
[[cell textLabel] setText: title];
[[cell detailTextLabel] setText: [NSString stringWithFormat: @"%d", [page intValue]+1]];
return cell;
}
- (void) tableView: (UITableView*)tableView didSelectRowAtIndexPath: (NSIndexPath*)indexPath
{
NSNumber *page = [pages objectAtIndex: [indexPath row]];
[target gotoPage: [page intValue] animated: NO];
[[self navigationController] popViewControllerAnimated: YES];
}
@end
|