Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7640 views
1
#import "MuDocumentController.h"
2
#import "MuOutlineController.h"
3
4
@implementation MuOutlineController
5
{
6
MuDocumentController *target;
7
NSMutableArray *titles;
8
NSMutableArray *pages;
9
}
10
11
- (id) initWithTarget: (id)aTarget titles: (NSMutableArray*)aTitles pages: (NSMutableArray*)aPages
12
{
13
self = [super initWithStyle: UITableViewStylePlain];
14
if (self) {
15
[self setTitle: @"Table of Contents"];
16
target = aTarget; // only keep a weak reference, to avoid retain cycles
17
titles = [aTitles retain];
18
pages = [aPages retain];
19
[[self tableView] setSeparatorStyle: UITableViewCellSeparatorStyleNone];
20
}
21
return self;
22
}
23
24
- (void) dealloc
25
{
26
[titles release];
27
[pages release];
28
[super dealloc];
29
}
30
31
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)o
32
{
33
return YES;
34
}
35
36
- (NSInteger) numberOfSectionsInTableView: (UITableView*)tableView
37
{
38
return 1;
39
}
40
41
- (NSInteger) tableView: (UITableView*)tableView numberOfRowsInSection: (NSInteger)section
42
{
43
return [titles count];
44
}
45
46
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
47
{
48
return 28;
49
}
50
51
- (UITableViewCell*) tableView: (UITableView*)tableView cellForRowAtIndexPath: (NSIndexPath*)indexPath
52
{
53
static NSString *cellid = @"MuCellIdent";
54
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellid];
55
if (!cell)
56
{
57
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier: cellid] autorelease];
58
[[cell textLabel] setFont: [UIFont systemFontOfSize: 16]];
59
[[cell detailTextLabel] setFont: [UIFont systemFontOfSize: 16]];
60
}
61
NSString *title = [titles objectAtIndex: [indexPath row]];
62
NSString *page = [pages objectAtIndex: [indexPath row]];
63
[[cell textLabel] setText: title];
64
[[cell detailTextLabel] setText: [NSString stringWithFormat: @"%d", [page intValue]+1]];
65
return cell;
66
}
67
68
- (void) tableView: (UITableView*)tableView didSelectRowAtIndexPath: (NSIndexPath*)indexPath
69
{
70
NSNumber *page = [pages objectAtIndex: [indexPath row]];
71
[target gotoPage: [page intValue] animated: NO];
72
[[self navigationController] popViewControllerAnimated: YES];
73
}
74
75
@end
76
77