project_files/HedgewarsMobile/Classes/SplitViewRootController.m
author koda
Sat, 31 Jul 2010 11:24:53 +0200
changeset 3697 d5b30d6373fc
parent 3662 a44406f4369b
child 3701 8c449776ebe6
permissions -rw-r--r--
remove trailing spaces from end of line
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.
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    23
    [super didReceiveMemoryWarning];
3547
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
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    30
// load the view programmatically; we need a splitViewController that handles a MasterViewController
3547
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];
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3547
diff changeset
    38
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    39
        self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    40
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    41
        UISplitViewController *splitViewRootController = [[UISplitViewController alloc] init];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    42
        splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    43
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    44
        MasterViewController *masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    45
        UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    46
        [masterViewController release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    47
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    48
        splitViewRootController.delegate = detailViewController;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    49
        masterViewController.detailViewController = detailViewController;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    50
        splitViewRootController.viewControllers = [NSArray arrayWithObjects: mainNavController, detailedNavController, nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    51
        [mainNavController release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
        [detailedNavController release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    53
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    54
        // add view to main controller
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    55
        [self.view addSubview:splitViewRootController.view];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    56
    } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
        [self.view addSubview:detailedNavController.view];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    58
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    59
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
    [super viewDidLoad];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    61
}
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    62
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    63
-(void) viewDidUnload {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    64
    detailViewController = nil;
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3547
diff changeset
    65
    MSG_DIDUNLOAD();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    66
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    67
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    68
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    69
-(void) dealloc {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
    [detailViewController release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    71
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    72
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    73
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    74
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    75
#pragma mark additional methods as we're using a UINavigationController programmatically
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    76
// see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    77
-(void) viewWillAppear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    78
    [super viewWillAppear:animated];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    79
    [detailViewController.navigationController viewWillAppear:animated];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    80
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    81
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    82
-(void) viewWillDisappear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    83
    [super viewWillDisappear:animated];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    84
    [detailViewController.navigationController viewWillDisappear: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) viewDidAppear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    88
    [super viewDidLoad];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    89
    [detailViewController.navigationController viewDidAppear: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) viewDidDisappear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    93
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    94
    [detailViewController.navigationController viewDidDisappear: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
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    98
@end