cocoaTouch/iPad/DetailViewController.m
author koda
Sat, 27 Mar 2010 16:57:18 +0000
changeset 3113 2829ea0dd47c
child 3165 3ec07a7d8456
permissions -rw-r--r--
* port fadeout to opengles * better notification mechanism * add a confirmation message before ending game * new structure for custom settings (splitview)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3113
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     1
    //
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     2
//  DetailViewController.m
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     3
//  HedgewarsMobile
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     4
//
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     5
//  Created by Vittorio on 27/03/10.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     7
//
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     8
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     9
#import "DetailViewController.h"
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    10
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    11
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    12
@implementation DetailViewController
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    13
@synthesize navigationBar, popoverController, detailItem, test;
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    14
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    15
/*
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    16
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    17
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    18
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    19
        // Custom initialization
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    20
    }
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    21
    return self;
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    22
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    23
*/
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    24
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    25
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    26
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    27
- (void)viewDidLoad {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    28
    [super viewDidLoad];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    29
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    30
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    31
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    32
- (void)didReceiveMemoryWarning {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    33
    // Releases the view if it doesn't have a superview.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    34
    [super didReceiveMemoryWarning];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    35
    
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    36
    // Release any cached data, images, etc that aren't in use.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    37
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    38
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    39
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    40
- (void)viewDidUnload {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    41
    [super viewDidUnload];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    42
    // Release any retained subviews of the main view.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    43
    // e.g. self.myOutlet = nil;
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    44
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    45
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    46
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    47
- (void)dealloc {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    48
    [navigationBar release];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    49
    [popoverController release];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    50
    [detailItem release];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    51
    [super dealloc];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    52
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    53
#pragma mark -
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    54
#pragma mark Managing the popover controller
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    55
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    56
/*
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    57
 When setting the detail item, update the view and dismiss the popover controller if it's showing.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    58
 */
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    59
-(void) setDetailItem:(id) newDetailItem {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    60
    if (detailItem != newDetailItem) {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    61
        [detailItem release];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    62
        detailItem = [newDetailItem retain];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    63
        
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    64
        // Update the view.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    65
        navigationBar.topItem.title = (NSString*) detailItem;
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    66
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    67
		test.text=(NSString*) detailItem;
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    68
    }
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    69
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    70
    if (popoverController != nil) {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    71
        [popoverController dismissPopoverAnimated:YES];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    72
    }        
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    73
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    74
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    75
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    76
#pragma mark -
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    77
#pragma mark Split view support
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    78
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    79
-(void) splitViewController:(UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    80
    barButtonItem.title = @"Master List";
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    81
    [navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:YES];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    82
    self.popoverController = pc;
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    83
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    84
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    85
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    86
// Called when the view is shown again in the split view, invalidating the button and popover controller.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    87
-(void) splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    88
    [navigationBar.topItem setLeftBarButtonItem:nil animated:YES];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    89
    self.popoverController = nil;
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    90
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    91
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    92
#pragma mark -
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    93
#pragma mark Rotation support
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    94
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    95
// Ensure that the view controller supports rotation and that the split view can therefore show in both portrait and landscape.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    96
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    97
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    98
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    99
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   100
-(IBAction) dismissSplitView {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   101
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   102
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   103
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   104
@end