cocoaTouch/iPad/DetailViewController.m
changeset 3305 91074496d5c9
parent 3304 8690a3aa93b5
child 3306 fcdf6d85b042
equal deleted inserted replaced
3304:8690a3aa93b5 3305:91074496d5c9
     1     //
       
     2 //  DetailViewController.m
       
     3 //  HedgewarsMobile
       
     4 //
       
     5 //  Created by Vittorio on 27/03/10.
       
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
       
     7 //
       
     8 
       
     9 #import "DetailViewController.h"
       
    10 #import "TeamSettingsViewController.h"
       
    11 
       
    12 @implementation DetailViewController
       
    13 @synthesize popoverController, detailItem, controllers;
       
    14 
       
    15 
       
    16 - (void)viewDidLoad {
       
    17     self.title =@"First";
       
    18     NSMutableArray *array= [[NSMutableArray alloc] init];
       
    19 
       
    20     TeamSettingsViewController *teamSettingsViewController = [[TeamSettingsViewController alloc] 
       
    21                                                               initWithStyle:UITableViewStyleGrouped];
       
    22     teamSettingsViewController.title = NSLocalizedString(@"Teams",@"");
       
    23     [array addObject:teamSettingsViewController];
       
    24     [teamSettingsViewController release];
       
    25     
       
    26     self.controllers = array;
       
    27     [array release];
       
    28         
       
    29     [super viewDidLoad];
       
    30 }
       
    31 
       
    32 - (void)didReceiveMemoryWarning {
       
    33     // Releases the view if it doesn't have a superview.
       
    34     [super didReceiveMemoryWarning];
       
    35 
       
    36     // Release any cached data, images, etc that aren't in use.
       
    37 }
       
    38 
       
    39 - (void)viewDidUnload {
       
    40     self.controllers = nil;
       
    41     self.popoverController = nil;
       
    42     self.detailItem = nil;
       
    43     [super viewDidUnload];
       
    44 }
       
    45 
       
    46 - (void)dealloc {
       
    47     [controllers release];
       
    48     [popoverController release];
       
    49     [detailItem release];
       
    50     [super dealloc];
       
    51 }
       
    52 
       
    53 #pragma mark -
       
    54 #pragma mark Table view data source
       
    55 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
       
    56     return 1;
       
    57 }
       
    58 
       
    59 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
       
    60     return [controllers count];
       
    61 }
       
    62 
       
    63 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
       
    64     static NSString *CellIdentifier = @"Cell";
       
    65     
       
    66     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
       
    67     if (cell == nil) {
       
    68         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
       
    69                                        reuseIdentifier:CellIdentifier] autorelease];
       
    70     }
       
    71     
       
    72     NSInteger row = [indexPath row];
       
    73     UITableViewController *controller = [controllers objectAtIndex:row];
       
    74     
       
    75     cell.textLabel.text = controller.title;
       
    76     cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
       
    77     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
       
    78     
       
    79     return cell;
       
    80 }
       
    81 
       
    82 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
       
    83     NSInteger row = [indexPath row];
       
    84     UITableViewController *nextController = [self.controllers objectAtIndex:row];
       
    85     [self.navigationController pushViewController:nextController animated:YES];
       
    86 }
       
    87 
       
    88 #pragma mark -
       
    89 #pragma mark Managing the popover controller
       
    90 // When setting the detail item, update the view and dismiss the popover controller if it's showing.
       
    91 -(void) setDetailItem:(id) newDetailItem {
       
    92     if (detailItem != newDetailItem) {
       
    93         [detailItem release];
       
    94         detailItem = [newDetailItem retain];
       
    95         
       
    96         // Update the view.
       
    97        // navigationBar.topItem.title = (NSString*) detailItem;
       
    98 
       
    99 		//test.text=(NSString*) detailItem;
       
   100     }
       
   101 
       
   102     if (popoverController != nil) {
       
   103         [popoverController dismissPopoverAnimated:YES];
       
   104     }        
       
   105 }
       
   106 
       
   107 #pragma mark -
       
   108 #pragma mark Split view support
       
   109 -(void) splitViewController:(UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {
       
   110     barButtonItem.title = @"Master List";
       
   111   //  [navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:YES];
       
   112     self.popoverController = pc;
       
   113 }
       
   114 
       
   115 // Called when the view is shown again in the split view, invalidating the button and popover controller.
       
   116 -(void) splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
       
   117   //  [navigationBar.topItem setLeftBarButtonItem:nil animated:YES];
       
   118     self.popoverController = nil;
       
   119 }
       
   120 
       
   121 #pragma mark -
       
   122 #pragma mark Rotation support
       
   123 // Ensure that the view controller supports rotation and that the split view can therefore show in both portrait and landscape.
       
   124 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
       
   125     return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
       
   126 }
       
   127 
       
   128 @end