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