cocoaTouch/SplitViewRootController.m
changeset 3321 988e39ef3c20
parent 3312 6d8f1c76756d
child 3323 091cf214bdd5
equal deleted inserted replaced
3320:506f7d6a82b3 3321:988e39ef3c20
     9 #import "SplitViewRootController.h"
     9 #import "SplitViewRootController.h"
    10 #import "MasterViewController.h"
    10 #import "MasterViewController.h"
    11 #import "DetailViewController.h"
    11 #import "DetailViewController.h"
    12 
    12 
    13 @implementation SplitViewRootController
    13 @implementation SplitViewRootController
    14 @synthesize splitViewRootController, masterViewController, detailViewController;
    14 @synthesize detailViewController;
    15 
    15 
    16 
    16 
    17 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    17 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    18     return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    18     return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    19 }
    19 }
    25 }
    25 }
    26 
    26 
    27 // load the view programmatically; we need a splitViewController that handles a MasterViewController 
    27 // load the view programmatically; we need a splitViewController that handles a MasterViewController 
    28 // (which is just a UITableViewController) and a DetailViewController where we present options
    28 // (which is just a UITableViewController) and a DetailViewController where we present options
    29 -(void) viewDidLoad {
    29 -(void) viewDidLoad {
    30     UINavigationController *detailedNavController;
    30     self.detailViewController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
    31     detailViewController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
    31      [detailViewController release];
       
    32            NSLog(@"%d", [detailViewController retainCount]);
    32 
    33 
    33     Class splitViewController = NSClassFromString(@"UISplitViewController");
    34     UINavigationController *detailedNavController = [[UINavigationController alloc] initWithRootViewController:self.detailViewController];
    34     if (splitViewController) {
    35             NSLog(@"%d", [detailViewController retainCount]);
    35         splitViewRootController = [[splitViewController alloc] init];
    36 
       
    37     [detailViewController release];
       
    38             NSLog(@"%d", [detailViewController retainCount]);
       
    39 
       
    40     id splitViewRootController;
       
    41     
       
    42     Class splitViewControllerClass = NSClassFromString(@"UISplitViewController");
       
    43     if (splitViewControllerClass) {
       
    44         splitViewRootController = [[splitViewControllerClass alloc] init];
    36         CGRect screensize = [[UIScreen mainScreen] bounds];
    45         CGRect screensize = [[UIScreen mainScreen] bounds];
    37         [[splitViewRootController view] setFrame:CGRectMake(0, 0, screensize.size.height, screensize.size.width)];
    46         [[splitViewRootController view] setFrame:CGRectMake(0, 0, screensize.size.height, screensize.size.width)];
    38         masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
    47         MasterViewController *masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
    39         
    48         
    40         UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
    49         UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
    41         detailedNavController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
    50     
    42         
    51         masterViewController.detailViewController = self.detailViewController;
    43         // set attributes
    52                 NSLog(@"%d", [detailViewController retainCount]);
    44         masterViewController.detailViewController = detailViewController;
    53 
       
    54         [masterViewController release];
       
    55 
    45         [splitViewRootController setViewControllers:[NSArray arrayWithObjects: mainNavController, detailedNavController, nil]];
    56         [splitViewRootController setViewControllers:[NSArray arrayWithObjects: mainNavController, detailedNavController, nil]];
    46         [mainNavController release];
    57         [mainNavController release];
    47         [detailedNavController release];
    58         [detailedNavController release];
    48         
    59         
    49         [splitViewRootController setDelegate: detailViewController];
    60         [splitViewRootController setDelegate: self.detailViewController];
    50         
    61         [detailViewController release];
       
    62                 NSLog(@"%d", [detailViewController retainCount]);
       
    63 
    51         // add view to main controller
    64         // add view to main controller
    52         [self.view addSubview:[splitViewRootController view]];
    65         [self.view addSubview:[splitViewRootController view]];
    53         [detailViewController release];
    66         //[splitViewRootController release];
    54         [masterViewController release];
    67 
    55     } else {
    68     } else {
    56         detailedNavController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
       
    57         [self.view addSubview:detailedNavController.view];
    69         [self.view addSubview:detailedNavController.view];
    58         // TODO: we are leaking here!!!
       
    59     }
    70     }
       
    71 
    60 
    72 
    61     [super viewDidLoad];
    73     [super viewDidLoad];
    62 }
    74 }
    63 
    75          
       
    76 -(void) viewDidUnload {
       
    77     [super viewDidUnload];
       
    78     self.detailViewController = nil;
       
    79 }
    64 -(void) dealloc {
    80 -(void) dealloc {
    65     [detailViewController release];
    81     [detailViewController release];
    66     [masterViewController release];
       
    67     [splitViewRootController release];
       
    68     [super dealloc];
    82     [super dealloc];
    69 }
    83 }
    70 
    84 
    71 #pragma mark -
    85 #pragma mark -
    72 #pragma mark additional methods as we're using a UINavigationController programmatically
    86 #pragma mark additional methods as we're using a UINavigationController programmatically