project_files/HedgewarsMobile/Classes/SplitViewRootController.m
changeset 3514 59dbd31e9953
parent 3513 f589230fa21b
child 3535 9e78c1f3d8d8
equal deleted inserted replaced
3513:f589230fa21b 3514:59dbd31e9953
       
     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 #import "CommodityFunctions.h"
       
    13 
       
    14 @implementation SplitViewRootController
       
    15 
       
    16 
       
    17 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
       
    18     return rotationManager(interfaceOrientation);
       
    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     if (detailViewController.view.superview == nil)
       
    26         detailViewController = nil;
       
    27     MSG_MEMCLEAN();
       
    28 }
       
    29 
       
    30 // load the view programmatically; we need a splitViewController that handles a MasterViewController 
       
    31 // (which is just a UITableViewController) and a DetailViewController where we present options
       
    32 -(void) viewDidLoad {
       
    33     detailViewController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
       
    34     UINavigationController *detailedNavController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
       
    35     [detailViewController release];
       
    36 
       
    37     CGRect rect = [[UIScreen mainScreen] bounds];
       
    38     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
       
    39         self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
       
    40         
       
    41     Class splitViewControllerClass = NSClassFromString(@"UISplitViewController");
       
    42     if (splitViewControllerClass) {
       
    43 #if __IPHONE_3_2
       
    44         UISplitViewController *splitViewRootController = [[UISplitViewController alloc] init];
       
    45         //splitViewRootController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;        
       
    46         splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
       
    47         
       
    48         MasterViewController *masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
       
    49         UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
       
    50         [masterViewController release];
       
    51 
       
    52         splitViewRootController.delegate = detailViewController;
       
    53         masterViewController.detailViewController = detailViewController;        
       
    54         splitViewRootController.viewControllers = [NSArray arrayWithObjects: mainNavController, detailedNavController, nil];
       
    55         [mainNavController release];
       
    56         [detailedNavController release];
       
    57         
       
    58         // add view to main controller
       
    59         [self.view addSubview:splitViewRootController.view];
       
    60 #endif
       
    61     } else {
       
    62         [self.view addSubview:detailedNavController.view];
       
    63     }
       
    64 
       
    65     [super viewDidLoad];
       
    66 }
       
    67          
       
    68 -(void) viewDidUnload {
       
    69     detailViewController = nil;
       
    70     [super viewDidUnload];
       
    71     MSG_DIDUNLOAD();
       
    72 }
       
    73 
       
    74 -(void) dealloc {
       
    75     [detailViewController release];
       
    76     [super dealloc];
       
    77 }
       
    78 -(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
       
    79     [detailViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
       
    80 }
       
    81 
       
    82 #pragma mark -
       
    83 #pragma mark additional methods as we're using a UINavigationController programmatically
       
    84 // see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/
       
    85 -(void) viewWillAppear:(BOOL)animated {
       
    86     [super viewWillAppear:animated];
       
    87     [detailViewController.navigationController viewWillAppear:animated];
       
    88 }
       
    89 
       
    90 -(void) viewWillDisappear:(BOOL)animated {
       
    91     [super viewWillDisappear:animated];
       
    92     [detailViewController.navigationController viewWillDisappear:animated];
       
    93 }
       
    94 
       
    95 -(void) viewDidAppear:(BOOL)animated {
       
    96     [super viewDidLoad];
       
    97     [detailViewController.navigationController viewDidAppear:animated];
       
    98 }
       
    99 
       
   100 -(void) viewDidDisappear:(BOOL)animated {
       
   101     [super viewDidUnload];
       
   102     [detailViewController.navigationController viewDidDisappear:animated];
       
   103 }
       
   104 
       
   105 
       
   106 @end