cocoaTouch/SplitViewRootController.m
author koda
Wed, 07 Apr 2010 03:02:19 +0000
changeset 3318 591c42242106
parent 3312 6d8f1c76756d
child 3321 988e39ef3c20
permissions -rw-r--r--
much better
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     1
    //
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     2
//  SplitViewRootController.m
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     3
//  HedgewarsMobile
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     4
//
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     5
//  Created by Vittorio on 27/03/10.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     7
//
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     8
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     9
#import "SplitViewRootController.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    10
#import "MasterViewController.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    11
#import "DetailViewController.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    12
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    13
@implementation SplitViewRootController
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    14
@synthesize splitViewRootController, masterViewController, detailViewController;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    15
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    16
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    17
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    18
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    19
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    20
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    21
-(void) didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    22
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    23
    [super didReceiveMemoryWarning];    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    24
    // Release any cached data, images, etc that aren't in use.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    25
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    26
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    27
// load the view programmatically; we need a splitViewController that handles a MasterViewController 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    28
// (which is just a UITableViewController) and a DetailViewController where we present options
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    29
-(void) viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    30
    UINavigationController *detailedNavController;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    31
    detailViewController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    32
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    33
    Class splitViewController = NSClassFromString(@"UISplitViewController");
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    34
    if (splitViewController) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    35
        splitViewRootController = [[splitViewController alloc] init];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    36
        CGRect screensize = [[UIScreen mainScreen] bounds];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    37
        [[splitViewRootController view] setFrame:CGRectMake(0, 0, screensize.size.height, screensize.size.width)];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    38
        masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    39
        
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    40
        UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    41
        detailedNavController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    42
        
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    43
        // set attributes
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    44
        masterViewController.detailViewController = detailViewController;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    45
        [splitViewRootController setViewControllers:[NSArray arrayWithObjects: mainNavController, detailedNavController, nil]];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    46
        [mainNavController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    47
        [detailedNavController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    48
        
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    49
        [splitViewRootController setDelegate: detailViewController];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    50
        
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    51
        // add view to main controller
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    52
        [self.view addSubview:[splitViewRootController view]];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    53
        [detailViewController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    54
        [masterViewController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    55
    } else {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    56
        detailedNavController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    57
        [self.view addSubview:detailedNavController.view];
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    58
        // TODO: we are leaking here!!!
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    60
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    61
    [super viewDidLoad];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    62
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    63
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
-(void) dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    65
    [detailViewController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    66
    [masterViewController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    67
    [splitViewRootController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    68
    [super dealloc];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    69
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    70
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    71
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    72
#pragma mark additional methods as we're using a UINavigationController programmatically
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    73
// see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    74
-(void) viewWillAppear:(BOOL)animated {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    75
    [super viewWillAppear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    76
    [detailViewController.navigationController viewWillAppear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    77
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    78
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    79
-(void) viewWillDisappear:(BOOL)animated {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    80
    [super viewWillDisappear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    81
    [detailViewController.navigationController viewWillDisappear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    82
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    83
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    84
-(void) viewDidAppear:(BOOL)animated {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    85
    [super viewDidLoad];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    86
    [detailViewController.navigationController viewDidAppear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    87
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    88
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    89
-(void) viewDidDisappear:(BOOL)animated {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    90
    [super viewDidUnload];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    91
    [detailViewController.navigationController viewDidDisappear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    92
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    93
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    94
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    95
@end