project_files/HedgewarsMobile/Classes/SettingsContainerViewController.m
branchhedgeroid
changeset 6224 42b256eca362
parent 6078 8c0cc07731e5
child 6319 b57a37a94ad3
equal deleted inserted replaced
6055:88cfcd9161d3 6224:42b256eca362
       
     1 /*
       
     2  * Hedgewars-iOS, a Hedgewars port for iOS devices
       
     3  * Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
       
    17  *
       
    18  * File created on 27/03/2010.
       
    19  */
       
    20 
       
    21 
       
    22 #import "SettingsContainerViewController.h"
       
    23 #import "SettingsBaseViewController.h"
       
    24 
       
    25 
       
    26 @implementation SettingsContainerViewController
       
    27 @synthesize baseController, activeController, splitViewRootController;
       
    28 
       
    29 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
       
    30     return rotationManager(interfaceOrientation);
       
    31 }
       
    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         SettingsBaseViewController *rightController = [[SettingsBaseViewController 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         SettingsBaseViewController *leftController = [[SettingsBaseViewController 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         if (nil == self.baseController) {
       
    63             SettingsBaseViewController *sbvc = [[SettingsBaseViewController alloc] init];
       
    64             self.baseController = sbvc;
       
    65             [sbvc release];
       
    66         }
       
    67         self.baseController.targetController = nil;
       
    68         self.baseController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
       
    69 
       
    70         [self.view addSubview:self.baseController.view];
       
    71         // here setting activeController is not needed as the event is kept active by the uitabbarcontroller
       
    72     }
       
    73 
       
    74     [super viewDidLoad];
       
    75 }
       
    76 
       
    77 #pragma mark -
       
    78 #pragma mark Memory management
       
    79 -(void) didReceiveMemoryWarning {
       
    80     if (self.baseController.view.superview == nil)
       
    81         self.baseController = nil;
       
    82     if (self.activeController.view.superview == nil)
       
    83         self.activeController = nil;
       
    84     if (self.splitViewRootController.view.superview == nil)
       
    85         self.splitViewRootController = nil;
       
    86     MSG_MEMCLEAN();
       
    87     [super didReceiveMemoryWarning];
       
    88 }
       
    89 
       
    90 -(void) viewDidUnload {
       
    91     self.baseController = nil;
       
    92     self.activeController = nil;
       
    93     self.splitViewRootController = nil;
       
    94     MSG_DIDUNLOAD();
       
    95     [super viewDidUnload];
       
    96 }
       
    97 
       
    98 -(void) dealloc {
       
    99     releaseAndNil(baseController);
       
   100     releaseAndNil(activeController);
       
   101     releaseAndNil(splitViewRootController);
       
   102     [super dealloc];
       
   103 }
       
   104 
       
   105 
       
   106 #pragma mark -
       
   107 #pragma mark additional methods as we're using a UINavigationController programmatically
       
   108 // see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/
       
   109 -(void) viewWillAppear:(BOOL)animated {
       
   110     [super viewWillAppear:animated];
       
   111     [self.activeController viewWillAppear:animated];
       
   112 }
       
   113 
       
   114 -(void) viewWillDisappear:(BOOL)animated {
       
   115     [super viewWillDisappear:animated];
       
   116     [self.activeController viewWillDisappear:animated];
       
   117 }
       
   118 
       
   119 -(void) viewDidAppear:(BOOL)animated {
       
   120     [super viewDidLoad];
       
   121     [self.activeController viewDidAppear:animated];
       
   122 }
       
   123 
       
   124 -(void) viewDidDisappear:(BOOL)animated {
       
   125     [super viewDidUnload];
       
   126     [self.activeController viewDidDisappear:animated];
       
   127 }
       
   128 
       
   129 
       
   130 @end