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