cocoaTouch/MasterViewController.m
author koda
Tue, 06 Apr 2010 18:14:15 +0000
changeset 3312 6d8f1c76756d
parent 3305 91074496d5c9
child 3316 52f0482b043f
permissions -rw-r--r--
restore and update the old general settings show hats in the team table
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"
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    11
#import "GeneralSettingsViewController.h"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    12
#import "TeamSettingsViewController.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    13
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    14
@implementation MasterViewController
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    15
@synthesize detailViewController, optionList, controllers;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    16
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    17
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    18
#pragma mark View lifecycle
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    21
- (void)viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    22
    [super viewDidLoad];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    23
    optionList = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    24
                                                  NSLocalizedString(@"Teams",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    25
                                                  NSLocalizedString(@"Weapons",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    26
                                                  NSLocalizedString(@"Schemes",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    27
                                                  nil];
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    28
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:0
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    29
                                                                                          target:self
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    30
                                                                                          action:@selector(dismissSplitView)];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    31
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    32
    NSMutableArray *array= [[NSMutableArray alloc] init];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    33
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    34
    GeneralSettingsViewController *generalSettingsViewController = [[GeneralSettingsViewController alloc]
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    35
                                                                    initWithStyle:UITableViewStyleGrouped];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    36
    generalSettingsViewController.title = NSLocalizedString(@"General",@"");
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    37
    generalSettingsViewController.navigationItem.hidesBackButton = YES;
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    38
    [array addObject:generalSettingsViewController];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    39
    [generalSettingsViewController release];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    40
    
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    41
    TeamSettingsViewController *teamSettingsViewController = [[TeamSettingsViewController alloc] 
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    42
                                                              initWithStyle:UITableViewStyleGrouped];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    43
    teamSettingsViewController.title = NSLocalizedString(@"Teams",@"");
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    44
    teamSettingsViewController.navigationItem.hidesBackButton = YES;
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    45
    [array addObject:teamSettingsViewController];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    46
    [teamSettingsViewController release];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    47
    
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    48
    self.controllers = array;
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    49
    [array release];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    50
    // Uncomment the following line to preserve selection between presentations.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    51
    //self.clearsSelectionOnViewWillAppear = NO;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    52
    // 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
    53
    //self.navigationItem.rightBarButtonItem = self.editButtonItem;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    54
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    55
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    56
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    57
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    60
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    61
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    62
#pragma mark Table view data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    63
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    65
    return 1;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    68
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    69
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    70
    return [optionList count];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    71
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    72
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
// Customize the appearance of table view cells.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    75
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    76
    static NSString *CellIdentifier = @"Cell";
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
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    79
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    80
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    81
        cell.textLabel.text = [optionList objectAtIndex:[indexPath row]];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    82
    }
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
    return cell;
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
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    88
// Override to support editing the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    89
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    90
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    91
    if (editingStyle == UITableViewCellEditingStyleDelete) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    92
        // Delete the row from the data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    93
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    94
    }   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    95
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    96
        // 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
    97
    }   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    98
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    99
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   100
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   101
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   102
// Override to support rearranging the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   103
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   104
}
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
// Override to support conditional rearranging of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   109
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   110
    // 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
   111
    return YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   112
}
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   115
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
#pragma mark Table view delegate
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   117
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   118
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
    [detailViewController.navigationController popToRootViewControllerAnimated:NO];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   120
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
   121
    NSInteger row = [indexPath row];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
   122
    UITableViewController *nextController = [self.controllers objectAtIndex:row];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
   123
    [detailViewController.navigationController pushViewController:nextController animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   124
}
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   128
#pragma mark Memory management
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   129
-(void) didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   130
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   131
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   132
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   133
    // Relinquish ownership any cached data, images, etc that aren't in use.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   134
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   135
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
- (void)dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
    [optionList release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   138
    [detailViewController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   139
    [super dealloc];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   140
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   141
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   142
-(IBAction) dismissSplitView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   143
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   144
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   145
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   146
@end
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   147