project_files/HedgewarsMobile/Classes/SplitViewRootController.m
author koda
Sun, 01 Aug 2010 17:58:09 +0200
changeset 3701 8c449776ebe6
parent 3697 d5b30d6373fc
child 3783 8e9daf967406
permissions -rw-r--r--
rewrite portions of some uiviewcontrollers
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
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    15
@synthesize activeController;
3547
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.
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    25
    if (self.activeController.view.superview == nil)
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    26
        self.activeController = nil;
3547
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 {
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    33
    CGRect rect = [[UIScreen mainScreen] bounds];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    34
    self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    36
    if (self.activeController == nil) {
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    37
        MasterViewController *rightController = [[MasterViewController alloc] initWithStyle:UITableViewStyleGrouped];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    38
        rightController.targetController = nil;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    39
        self.activeController = rightController;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    40
        [rightController release];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    41
    }
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    42
    UINavigationController *rightNavController = [[UINavigationController alloc] initWithRootViewController:self.activeController];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    43
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
    44
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    45
        MasterViewController *leftController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    46
        leftController.targetController = self.activeController;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    47
        UINavigationController *leftNavController = [[UINavigationController alloc] initWithRootViewController:leftController];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    48
        [leftController release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    49
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    50
        UISplitViewController *splitViewRootController = [[UISplitViewController alloc] init];
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    51
        splitViewRootController.delegate = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
        splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    53
        splitViewRootController.viewControllers = [NSArray arrayWithObjects: leftNavController, rightNavController, nil];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    54
        [leftNavController release];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    55
        [rightNavController release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    56
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
        // add view to main controller
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    58
        [self.view addSubview:splitViewRootController.view];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    59
    } else {
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    60
        rightNavController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    61
        [self.view addSubview:rightNavController.view];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    63
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    64
    [super viewDidLoad];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    65
}
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    66
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    67
-(void) viewDidUnload {
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    68
    self.activeController = 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
    69
    MSG_DIDUNLOAD();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    71
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    72
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    73
-(void) dealloc {
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    74
    [self.activeController release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    75
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    76
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    77
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    78
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    79
#pragma mark additional methods as we're using a UINavigationController programmatically
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    80
// see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    81
-(void) viewWillAppear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    82
    [super viewWillAppear:animated];
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    83
    [self.activeController.navigationController viewWillAppear:animated];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    84
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    85
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    86
-(void) viewWillDisappear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    87
    [super viewWillDisappear:animated];
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    88
    [self.activeController.navigationController viewWillDisappear:animated];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    89
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    90
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    91
-(void) viewDidAppear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    92
    [super viewDidLoad];
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    93
    [self.activeController.navigationController viewDidAppear:animated];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    94
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    95
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    96
-(void) viewDidDisappear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    97
    [super viewDidUnload];
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    98
    [self.activeController.navigationController viewDidDisappear:animated];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    99
}
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
@end