cocoaTouch/MasterViewController.m
author koda
Tue, 13 Apr 2010 22:45:46 +0000
changeset 3340 96dd168b080b
parent 3335 2520ee7a5484
child 3352 ac5d14a35482
permissions -rw-r--r--
fix all of what was committed before
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"
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    13
#import "CommodityFunctions.h"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    14
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    15
@implementation MasterViewController
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    16
@synthesize detailViewController, optionList, controllers, lastIndexPath;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    17
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    18
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    19
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    20
	return rotationManager(interfaceOrientation);
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    21
}
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    22
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    23
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    24
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    25
#pragma mark View lifecycle
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    26
- (void)viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    27
    [super viewDidLoad];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    28
    
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    29
    // the list of selectable controllers
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    30
    optionList = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    31
                                                  NSLocalizedString(@"Teams",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    32
                                                  NSLocalizedString(@"Weapons",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    33
                                                  NSLocalizedString(@"Schemes",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    34
                                                  nil];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    35
    // the "Done" button on top left
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    36
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:0
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    37
                                                                                          target:self
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    38
                                                                                          action:@selector(dismissSplitView)];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    39
    // list of allocated viewcontrollers (same in DetailViewController)
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    40
    NSMutableArray *array= [[NSMutableArray alloc] init];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    41
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    42
    GeneralSettingsViewController *generalSettingsViewController = [[GeneralSettingsViewController alloc]
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    43
                                                                    initWithStyle:UITableViewStyleGrouped];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    44
    generalSettingsViewController.title = NSLocalizedString(@"General",@"");
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    45
    generalSettingsViewController.navigationItem.hidesBackButton = YES;
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    46
    [array addObject:generalSettingsViewController];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    47
    [generalSettingsViewController release];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    48
    
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    49
    TeamSettingsViewController *teamSettingsViewController = [[TeamSettingsViewController alloc] 
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    50
                                                              initWithStyle:UITableViewStyleGrouped];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    51
    teamSettingsViewController.title = NSLocalizedString(@"Teams",@"");
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    52
    teamSettingsViewController.navigationItem.hidesBackButton = YES;
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    53
    [array addObject:teamSettingsViewController];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    54
    [teamSettingsViewController release];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    55
    
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    56
    self.controllers = array;
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    57
    [array release];
3305
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    61
#pragma mark Table view data source
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
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
    return 1;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    68
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    69
    return [optionList count];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    70
}
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
// Customize the appearance of table view cells.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    74
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    75
    static NSString *CellIdentifier = @"Cell";
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
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    78
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    79
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    80
        cell.textLabel.text = [optionList objectAtIndex:[indexPath row]];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    81
    }
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
    return cell;
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 editing the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    88
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    89
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    90
    if (editingStyle == UITableViewCellEditingStyleDelete) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    91
        // Delete the row from the data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    92
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
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
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    95
        // 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
    96
    }   
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
// Override to support rearranging the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   102
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
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
*/
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
// Override to support conditional rearranging of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   108
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   109
    // 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
   110
    return YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   111
}
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   115
#pragma mark Table view delegate
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   117
    int newRow = [indexPath row];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   118
    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : 0;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
    
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   120
    if (newRow != oldRow) {
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   121
        [detailViewController.navigationController popToRootViewControllerAnimated:NO];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   122
        
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   123
        UITableViewController *nextController = [self.controllers objectAtIndex:[indexPath row]];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   124
        [detailViewController.navigationController pushViewController:nextController animated:YES];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   125
        self.lastIndexPath = indexPath;
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   126
        [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   127
    }
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   128
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   129
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   130
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   131
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   132
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   133
#pragma mark Memory management
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   134
-(void) didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   135
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
    // Relinquish ownership any cached data, images, etc that aren't in use.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   138
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   139
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   140
- (void)dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   141
    [optionList release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   142
    [detailViewController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   143
    [super dealloc];
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
-(IBAction) dismissSplitView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   147
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   148
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   149
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   150
@end
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   151