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