cocoaTouch/MasterViewController.m
changeset 3305 91074496d5c9
child 3312 6d8f1c76756d
equal deleted inserted replaced
3304:8690a3aa93b5 3305:91074496d5c9
       
     1 //
       
     2 //  MasterViewController.m
       
     3 //  HedgewarsMobile
       
     4 //
       
     5 //  Created by Vittorio on 27/03/10.
       
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
       
     7 //
       
     8 
       
     9 #import "MasterViewController.h"
       
    10 #import "DetailViewController.h"
       
    11 #import "TeamSettingsViewController.h"
       
    12 
       
    13 @implementation MasterViewController
       
    14 @synthesize detailViewController, optionList;
       
    15 
       
    16 #pragma mark -
       
    17 #pragma mark View lifecycle
       
    18 
       
    19 
       
    20 - (void)viewDidLoad {
       
    21     [super viewDidLoad];
       
    22     optionList = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""),
       
    23                                                   NSLocalizedString(@"Teams",@""),
       
    24                                                   NSLocalizedString(@"Weapons",@""),
       
    25                                                   NSLocalizedString(@"Schemes",@""),
       
    26                                                   nil];
       
    27     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:0 target:self action:@selector(dismissSplitView)];
       
    28 
       
    29     // Uncomment the following line to preserve selection between presentations.
       
    30     //self.clearsSelectionOnViewWillAppear = NO;
       
    31     // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
       
    32     //self.navigationItem.rightBarButtonItem = self.editButtonItem;
       
    33 }
       
    34 
       
    35 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
       
    36     return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
       
    37 }
       
    38 
       
    39 
       
    40 #pragma mark -
       
    41 #pragma mark Table view data source
       
    42 
       
    43 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
       
    44     return 1;
       
    45 }
       
    46 
       
    47 
       
    48 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
       
    49     return [optionList count];
       
    50 }
       
    51 
       
    52 
       
    53 // Customize the appearance of table view cells.
       
    54 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
       
    55     static NSString *CellIdentifier = @"Cell";
       
    56     
       
    57     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
       
    58     if (cell == nil) {
       
    59         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
       
    60         cell.textLabel.text = [optionList objectAtIndex:[indexPath row]];
       
    61     }
       
    62     
       
    63     return cell;
       
    64 }
       
    65 
       
    66 /*
       
    67 // Override to support editing the table view.
       
    68 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
       
    69     
       
    70     if (editingStyle == UITableViewCellEditingStyleDelete) {
       
    71         // Delete the row from the data source
       
    72         [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
       
    73     }   
       
    74     else if (editingStyle == UITableViewCellEditingStyleInsert) {
       
    75         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
       
    76     }   
       
    77 }
       
    78 */
       
    79 
       
    80 /*
       
    81 // Override to support rearranging the table view.
       
    82 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
       
    83 }
       
    84 */
       
    85 
       
    86 /*
       
    87 // Override to support conditional rearranging of the table view.
       
    88 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
       
    89     // Return NO if you do not want the item to be re-orderable.
       
    90     return YES;
       
    91 }
       
    92 */
       
    93 
       
    94 #pragma mark -
       
    95 #pragma mark Table view delegate
       
    96 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
       
    97     
       
    98     [detailViewController.navigationController popToRootViewControllerAnimated:NO];
       
    99     TeamSettingsViewController *teamSettingsViewController = [[TeamSettingsViewController alloc] 
       
   100                                                               initWithStyle:UITableViewStyleGrouped];
       
   101     teamSettingsViewController.title = [optionList objectAtIndex:[indexPath row]];
       
   102     teamSettingsViewController.navigationItem.hidesBackButton = YES;
       
   103 
       
   104     [detailViewController.navigationController pushViewController: teamSettingsViewController animated:YES];
       
   105 }
       
   106 
       
   107 
       
   108 #pragma mark -
       
   109 #pragma mark Memory management
       
   110 -(void) didReceiveMemoryWarning {
       
   111     // Releases the view if it doesn't have a superview.
       
   112     [super didReceiveMemoryWarning];
       
   113     
       
   114     // Relinquish ownership any cached data, images, etc that aren't in use.
       
   115 }
       
   116 
       
   117 - (void)dealloc {
       
   118     [optionList release];
       
   119     [detailViewController release];
       
   120     [super dealloc];
       
   121 }
       
   122 
       
   123 -(IBAction) dismissSplitView {
       
   124     [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
       
   125 }
       
   126 
       
   127 @end
       
   128