3305
|
1 |
//
|
|
2 |
// SplitViewRootController.m
|
|
3 |
// HedgewarsMobile
|
|
4 |
//
|
|
5 |
// Created by Vittorio on 27/03/10.
|
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved.
|
|
7 |
//
|
|
8 |
|
|
9 |
#import "SplitViewRootController.h"
|
|
10 |
#import "MasterViewController.h"
|
|
11 |
#import "DetailViewController.h"
|
3335
|
12 |
#import "CommodityFunctions.h"
|
3305
|
13 |
|
|
14 |
@implementation SplitViewRootController
|
3321
|
15 |
@synthesize detailViewController;
|
3305
|
16 |
|
|
17 |
|
|
18 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
3335
|
19 |
return rotationManager(interfaceOrientation);
|
3305
|
20 |
}
|
|
21 |
|
|
22 |
-(void) didReceiveMemoryWarning {
|
|
23 |
// Releases the view if it doesn't have a superview.
|
|
24 |
[super didReceiveMemoryWarning];
|
|
25 |
// Release any cached data, images, etc that aren't in use.
|
|
26 |
}
|
|
27 |
|
|
28 |
// load the view programmatically; we need a splitViewController that handles a MasterViewController
|
|
29 |
// (which is just a UITableViewController) and a DetailViewController where we present options
|
|
30 |
-(void) viewDidLoad {
|
3321
|
31 |
self.detailViewController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
3335
|
32 |
[detailViewController release];
|
3321
|
33 |
UINavigationController *detailedNavController = [[UINavigationController alloc] initWithRootViewController:self.detailViewController];
|
|
34 |
[detailViewController release];
|
|
35 |
|
|
36 |
id splitViewRootController;
|
|
37 |
|
|
38 |
Class splitViewControllerClass = NSClassFromString(@"UISplitViewController");
|
|
39 |
if (splitViewControllerClass) {
|
|
40 |
splitViewRootController = [[splitViewControllerClass alloc] init];
|
3305
|
41 |
CGRect screensize = [[UIScreen mainScreen] bounds];
|
|
42 |
[[splitViewRootController view] setFrame:CGRectMake(0, 0, screensize.size.height, screensize.size.width)];
|
3321
|
43 |
MasterViewController *masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
|
3305
|
44 |
|
|
45 |
UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
|
3321
|
46 |
|
|
47 |
masterViewController.detailViewController = self.detailViewController;
|
|
48 |
|
|
49 |
[masterViewController release];
|
|
50 |
|
3305
|
51 |
[splitViewRootController setViewControllers:[NSArray arrayWithObjects: mainNavController, detailedNavController, nil]];
|
|
52 |
[mainNavController release];
|
|
53 |
[detailedNavController release];
|
|
54 |
|
3335
|
55 |
[splitViewRootController setDelegate:self.detailViewController];
|
3321
|
56 |
[detailViewController release];
|
|
57 |
|
3305
|
58 |
// add view to main controller
|
|
59 |
[self.view addSubview:[splitViewRootController view]];
|
3321
|
60 |
//[splitViewRootController release];
|
|
61 |
|
3305
|
62 |
} else {
|
|
63 |
[self.view addSubview:detailedNavController.view];
|
|
64 |
}
|
|
65 |
|
3321
|
66 |
|
3305
|
67 |
[super viewDidLoad];
|
|
68 |
}
|
3321
|
69 |
|
|
70 |
-(void) viewDidUnload {
|
|
71 |
[super viewDidUnload];
|
|
72 |
self.detailViewController = nil;
|
|
73 |
}
|
3305
|
74 |
-(void) dealloc {
|
|
75 |
[detailViewController release];
|
|
76 |
[super dealloc];
|
|
77 |
}
|
|
78 |
|
|
79 |
#pragma mark -
|
|
80 |
#pragma mark additional methods as we're using a UINavigationController programmatically
|
|
81 |
// see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/
|
|
82 |
-(void) viewWillAppear:(BOOL)animated {
|
|
83 |
[super viewWillAppear:animated];
|
|
84 |
[detailViewController.navigationController viewWillAppear:animated];
|
|
85 |
}
|
|
86 |
|
|
87 |
-(void) viewWillDisappear:(BOOL)animated {
|
|
88 |
[super viewWillDisappear:animated];
|
|
89 |
[detailViewController.navigationController viewWillDisappear:animated];
|
|
90 |
}
|
|
91 |
|
|
92 |
-(void) viewDidAppear:(BOOL)animated {
|
|
93 |
[super viewDidLoad];
|
|
94 |
[detailViewController.navigationController viewDidAppear:animated];
|
|
95 |
}
|
|
96 |
|
|
97 |
-(void) viewDidDisappear:(BOOL)animated {
|
|
98 |
[super viewDidUnload];
|
|
99 |
[detailViewController.navigationController viewDidDisappear:animated];
|
|
100 |
}
|
|
101 |
|
|
102 |
|
|
103 |
@end
|