project_files/HedgewarsMobile/Classes/SplitViewRootController.m
author legutus
Mon, 30 Aug 2010 15:24:49 +0200
changeset 3786 0907b0fd5714
parent 3783 8e9daf967406
child 3829 81db3c85784b
permissions -rw-r--r--
Improves room list with filter for state/rules/weapons and general search
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 "CommodityFunctions.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    12
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    13
@implementation SplitViewRootController
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    14
@synthesize activeController;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    15
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    16
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    17
    return rotationManager(interfaceOrientation);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    18
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    19
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    20
-(void) didReceiveMemoryWarning {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
    // Releases the view if it doesn't have a superview.
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    22
    [super didReceiveMemoryWarning];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    23
    // Release any cached data, images, etc that aren't in use.
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    24
    if (self.activeController.view.superview == nil)
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    25
        self.activeController = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
    MSG_MEMCLEAN();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    28
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    29
// load the view programmatically; we need a splitViewController that handles a MasterViewController
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
// (which is just a UITableViewController) and a DetailViewController where we present options
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
-(void) viewDidLoad {
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    32
    CGRect rect = [[UIScreen mainScreen] bounds];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    33
    self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    35
    if (self.activeController == nil) {
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    36
        MasterViewController *rightController = [[MasterViewController alloc] initWithStyle:UITableViewStyleGrouped];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    37
        rightController.targetController = nil;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    38
        self.activeController = rightController;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    39
        [rightController release];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    40
    }
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    41
    UINavigationController *rightNavController = [[UINavigationController alloc] initWithRootViewController:self.activeController];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    42
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
    43
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    44
        MasterViewController *leftController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    45
        leftController.targetController = self.activeController;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    46
        UINavigationController *leftNavController = [[UINavigationController alloc] initWithRootViewController:leftController];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    47
        [leftController release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    48
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
        UISplitViewController *splitViewRootController = [[UISplitViewController alloc] init];
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    50
        splitViewRootController.delegate = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    51
        splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    52
        splitViewRootController.viewControllers = [NSArray arrayWithObjects: leftNavController, rightNavController, nil];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    53
        [leftNavController release];
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    54
        [rightNavController release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    55
3547
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 {
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    59
        rightNavController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    60
        [self.view addSubview:rightNavController.view];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    61
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    63
    [super viewDidLoad];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    64
}
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    65
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    66
-(void) viewDidUnload {
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    67
    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
    68
    MSG_DIDUNLOAD();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    69
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    71
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    72
-(void) dealloc {
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    73
    [self.activeController release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    74
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    75
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    76
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    77
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    78
#pragma mark additional methods as we're using a UINavigationController programmatically
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    79
// see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    80
-(void) viewWillAppear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    81
    [super viewWillAppear:animated];
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    82
    [self.activeController.navigationController viewWillAppear:animated];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    83
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    84
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    85
-(void) viewWillDisappear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    86
    [super viewWillDisappear:animated];
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    87
    [self.activeController.navigationController viewWillDisappear:animated];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    88
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    89
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    90
-(void) viewDidAppear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    91
    [super viewDidLoad];
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    92
    [self.activeController.navigationController viewDidAppear:animated];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    93
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    94
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    95
-(void) viewDidDisappear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    96
    [super viewDidUnload];
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    97
    [self.activeController.navigationController viewDidDisappear:animated];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    98
}
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
@end