project_files/HedgewarsMobile/Classes/SplitViewRootController.m
changeset 6074 047eaed35cbb
parent 6000 dbcebcd3d79f
equal deleted inserted replaced
6073:e6ce1a337e0f 6074:047eaed35cbb
    22 #import "SplitViewRootController.h"
    22 #import "SplitViewRootController.h"
    23 #import "MasterViewController.h"
    23 #import "MasterViewController.h"
    24 #import "CommodityFunctions.h"
    24 #import "CommodityFunctions.h"
    25 
    25 
    26 @implementation SplitViewRootController
    26 @implementation SplitViewRootController
    27 @synthesize activeController, rightNavController, splitViewRootController;
    27 @synthesize activeController, splitViewRootController;
    28 
    28 
    29 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    29 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    30     return rotationManager(interfaceOrientation);
    30     return rotationManager(interfaceOrientation);
    31 }
    31 }
    32 
    32 
       
    33 
       
    34 -(void) viewDidLoad {
       
    35     CGRect rect = [[UIScreen mainScreen] bounds];
       
    36     self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
       
    37 
       
    38     if (IS_IPAD()) {
       
    39         // the contents on the right of the splitview, setting targetController to nil to avoid creating the table
       
    40         MasterViewController *rightController = [[MasterViewController alloc] init];
       
    41         rightController.targetController = nil;
       
    42         UINavigationController *rightNavController = [[UINavigationController alloc] initWithRootViewController:rightController];
       
    43         [rightController release];
       
    44 
       
    45         // the contens on the left of the splitview, setting targetController that will receive push/pop actions
       
    46         MasterViewController *leftController = [[MasterViewController alloc] init];
       
    47         leftController.targetController = rightNavController.topViewController;
       
    48         UINavigationController *leftNavController = [[UINavigationController alloc] initWithRootViewController:leftController];
       
    49         [leftController release];
       
    50 
       
    51         self.activeController = rightNavController;
       
    52         self.splitViewRootController = [[UISplitViewController alloc] init];
       
    53         self.splitViewRootController.delegate = nil;
       
    54         self.splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
       
    55         self.splitViewRootController.viewControllers = [NSArray arrayWithObjects: leftNavController, rightNavController, nil];
       
    56         [leftNavController release];
       
    57         [rightNavController release];
       
    58 
       
    59         // add view to main controller
       
    60         [self.view addSubview:self.splitViewRootController.view];
       
    61     } else {
       
    62         MasterViewController *mainController = [[MasterViewController alloc] init];
       
    63         mainController.targetController = nil;
       
    64         mainController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
       
    65         [self.view addSubview:mainController.view];
       
    66         // here setting activeController is not needed as the event is kept active by the uitabbarcontroller
       
    67     }
       
    68 
       
    69     [super viewDidLoad];
       
    70 }
       
    71 
       
    72 #pragma mark -
       
    73 #pragma mark Memory management
    33 -(void) didReceiveMemoryWarning {
    74 -(void) didReceiveMemoryWarning {
       
    75     if (self.splitViewRootController.view.superview == nil)
       
    76         self.splitViewRootController = nil;
    34     if (self.activeController.view.superview == nil)
    77     if (self.activeController.view.superview == nil)
    35         self.activeController = nil;
    78         self.activeController = nil;
    36     MSG_MEMCLEAN();
    79     MSG_MEMCLEAN();
    37     [super didReceiveMemoryWarning];
    80     [super didReceiveMemoryWarning];
    38 }
    81 }
    39 
    82 
    40 // load the view programmatically; we need a splitViewController that handles a MasterViewController
       
    41 // (which is just a UITableViewController) and a DetailViewController where we present options
       
    42 -(void) viewDidLoad {
       
    43     CGRect rect = [[UIScreen mainScreen] bounds];
       
    44     self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
       
    45 
       
    46     if (self.activeController == nil) {
       
    47         MasterViewController *rightController = [[MasterViewController alloc] initWithStyle:UITableViewStyleGrouped];
       
    48         rightController.rootController = self;
       
    49         rightController.targetController = nil;
       
    50         self.activeController = rightController;
       
    51         [rightController release];
       
    52     }
       
    53     self.rightNavController = [[UINavigationController alloc] initWithRootViewController:self.activeController];
       
    54 
       
    55     if (IS_IPAD()) {
       
    56         MasterViewController *leftController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
       
    57         leftController.rootController = self;
       
    58         leftController.targetController = self.activeController;
       
    59         UINavigationController *leftNavController = [[UINavigationController alloc] initWithRootViewController:leftController];
       
    60         [leftController release];
       
    61 
       
    62         self.splitViewRootController = [[UISplitViewController alloc] init];
       
    63         self.splitViewRootController.delegate = nil;
       
    64         self.splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
       
    65         self.splitViewRootController.viewControllers = [NSArray arrayWithObjects: leftNavController, self.rightNavController, nil];
       
    66         [leftNavController release];
       
    67         [self.rightNavController release];
       
    68 
       
    69         // add view to main controller
       
    70         [self.view addSubview:self.splitViewRootController.view];
       
    71     } else {
       
    72         self.rightNavController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
       
    73         [self.view addSubview:self.rightNavController.view];
       
    74     }
       
    75 
       
    76     [super viewDidLoad];
       
    77 }
       
    78 
       
    79 -(void) dismissModalViewControllerAnimated:(BOOL)animated {
       
    80     [AudioManagerController playBackSound];
       
    81     [self.parentViewController dismissModalViewControllerAnimated:YES];
       
    82 }
       
    83 
       
    84 -(void) viewDidUnload {
    83 -(void) viewDidUnload {
    85     self.activeController = nil;
    84     self.activeController = nil;
    86     self.rightNavController = nil;
       
    87     self.splitViewRootController = nil;
    85     self.splitViewRootController = nil;
    88     MSG_DIDUNLOAD();
    86     MSG_DIDUNLOAD();
    89     [super viewDidUnload];
    87     [super viewDidUnload];
    90 }
    88 }
    91 
    89 
    92 -(void) dealloc {
    90 -(void) dealloc {
    93     releaseAndNil(activeController);
    91     releaseAndNil(activeController);
    94     releaseAndNil(rightNavController);
       
    95     releaseAndNil(splitViewRootController);
    92     releaseAndNil(splitViewRootController);
    96     [super dealloc];
    93     [super dealloc];
    97 }
    94 }
       
    95 
    98 
    96 
    99 #pragma mark -
    97 #pragma mark -
   100 #pragma mark additional methods as we're using a UINavigationController programmatically
    98 #pragma mark additional methods as we're using a UINavigationController programmatically
   101 // see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/
    99 // see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/
   102 -(void) viewWillAppear:(BOOL)animated {
   100 -(void) viewWillAppear:(BOOL)animated {
   103     [super viewWillAppear:animated];
   101     [super viewWillAppear:animated];
   104     [self.activeController.navigationController viewWillAppear:animated];
   102     [self.activeController viewWillAppear:animated];
   105 }
   103 }
   106 
   104 
   107 -(void) viewWillDisappear:(BOOL)animated {
   105 -(void) viewWillDisappear:(BOOL)animated {
   108     [super viewWillDisappear:animated];
   106     [super viewWillDisappear:animated];
   109     [self.activeController.navigationController viewWillDisappear:animated];
   107     [self.activeController viewWillDisappear:animated];
   110 }
   108 }
   111 
   109 
   112 -(void) viewDidAppear:(BOOL)animated {
   110 -(void) viewDidAppear:(BOOL)animated {
   113     [super viewDidLoad];
   111     [super viewDidLoad];
   114     [self.activeController.navigationController viewDidAppear:animated];
   112     [self.activeController viewDidAppear:animated];
   115 }
   113 }
   116 
   114 
   117 -(void) viewDidDisappear:(BOOL)animated {
   115 -(void) viewDidDisappear:(BOOL)animated {
   118     [super viewDidUnload];
   116     [super viewDidUnload];
   119     [self.activeController.navigationController viewDidDisappear:animated];
   117     [self.activeController viewDidDisappear:animated];
   120 }
   118 }
   121 
   119 
   122 
   120 
   123 @end
   121 @end