project_files/HedgewarsMobile/Classes/SplitViewRootController.m
author koda
Wed, 23 Jun 2010 01:00:52 +0200
changeset 3535 9e78c1f3d8d8
parent 3514 59dbd31e9953
child 3546 ccf4854df294
permissions -rw-r--r--
update the project to ios4 by removing pre-3.2 references add missing lowres image other smaller fixes
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"
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3332
diff changeset
    12
#import "CommodityFunctions.h"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    13
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    14
@implementation SplitViewRootController
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 {
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3332
diff changeset
    18
    return rotationManager(interfaceOrientation);
3305
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.
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3487
diff changeset
    25
    if (detailViewController.view.superview == nil)
016b3172b645 a bunch of minor stuff
koda
parents: 3487
diff changeset
    26
        detailViewController = nil;
3487
b1d00f1950c8 add some memory aware code
koda
parents: 3465
diff changeset
    27
    MSG_MEMCLEAN();
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    28
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    29
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    30
// load the view programmatically; we need a splitViewController that handles a MasterViewController 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    31
// (which is just a UITableViewController) and a DetailViewController where we present options
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    32
-(void) viewDidLoad {
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3365
diff changeset
    33
    detailViewController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3365
diff changeset
    34
    UINavigationController *detailedNavController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
3321
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3312
diff changeset
    35
    [detailViewController release];
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3312
diff changeset
    36
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3487
diff changeset
    37
    CGRect rect = [[UIScreen mainScreen] bounds];
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3365
diff changeset
    38
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3487
diff changeset
    39
        self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
016b3172b645 a bunch of minor stuff
koda
parents: 3487
diff changeset
    40
        
3535
9e78c1f3d8d8 update the project to ios4 by removing pre-3.2 references
koda
parents: 3514
diff changeset
    41
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
3465
b290993c0810 unbreak stuff
koda
parents: 3464
diff changeset
    42
        UISplitViewController *splitViewRootController = [[UISplitViewController alloc] init];
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3487
diff changeset
    43
        //splitViewRootController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;        
016b3172b645 a bunch of minor stuff
koda
parents: 3487
diff changeset
    44
        splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3365
diff changeset
    45
        
3321
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3312
diff changeset
    46
        MasterViewController *masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    47
        UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
3321
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3312
diff changeset
    48
        [masterViewController release];
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3312
diff changeset
    49
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3487
diff changeset
    50
        splitViewRootController.delegate = detailViewController;
016b3172b645 a bunch of minor stuff
koda
parents: 3487
diff changeset
    51
        masterViewController.detailViewController = detailViewController;        
3465
b290993c0810 unbreak stuff
koda
parents: 3464
diff changeset
    52
        splitViewRootController.viewControllers = [NSArray arrayWithObjects: mainNavController, detailedNavController, nil];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    53
        [mainNavController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    54
        [detailedNavController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    55
        
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    56
        // add view to main controller
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3487
diff changeset
    57
        [self.view addSubview:splitViewRootController.view];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
    } else {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
        [self.view addSubview:detailedNavController.view];
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    62
    [super viewDidLoad];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    63
}
3321
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3312
diff changeset
    64
         
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3312
diff changeset
    65
-(void) viewDidUnload {
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3365
diff changeset
    66
    detailViewController = nil;
3321
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3312
diff changeset
    67
    [super viewDidUnload];
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3487
diff changeset
    68
    MSG_DIDUNLOAD();
3321
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3312
diff changeset
    69
}
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3365
diff changeset
    70
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    71
-(void) dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    72
    [detailViewController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    73
    [super dealloc];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    74
}
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3487
diff changeset
    75
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
016b3172b645 a bunch of minor stuff
koda
parents: 3487
diff changeset
    76
    [detailViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
016b3172b645 a bunch of minor stuff
koda
parents: 3487
diff changeset
    77
}
3305
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    80
#pragma mark additional methods as we're using a UINavigationController programmatically
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    81
// 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
    82
-(void) viewWillAppear:(BOOL)animated {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    83
    [super viewWillAppear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    84
    [detailViewController.navigationController viewWillAppear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    85
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    86
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    87
-(void) viewWillDisappear:(BOOL)animated {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    88
    [super viewWillDisappear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    89
    [detailViewController.navigationController viewWillDisappear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    90
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    91
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    92
-(void) viewDidAppear:(BOOL)animated {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    93
    [super viewDidLoad];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    94
    [detailViewController.navigationController viewDidAppear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    95
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    96
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    97
-(void) viewDidDisappear:(BOOL)animated {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    98
    [super viewDidUnload];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    99
    [detailViewController.navigationController viewDidDisappear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   100
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   101
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   102
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   103
@end