cocoaTouch/MasterViewController.m
author sheepluva
Wed, 07 Apr 2010 16:03:21 +0000
changeset 3322 80afcb97eb46
parent 3316 52f0482b043f
child 3335 2520ee7a5484
permissions -rw-r--r--
* INSTALL file: setting FreePascal to >= 2.2.0 * engine: some more value caching
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
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    15
@synthesize detailViewController, optionList, controllers, lastIndexPath;
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
- (void)viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    20
    [super viewDidLoad];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    21
    
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    22
    // the list of selectable controllers
3305
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];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    28
    // the "Done" button on top left
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    29
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:0
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    30
                                                                                          target:self
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    31
                                                                                          action:@selector(dismissSplitView)];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    32
    // list of allocated viewcontrollers (same in DetailViewController)
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    33
    NSMutableArray *array= [[NSMutableArray alloc] init];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    34
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    35
    GeneralSettingsViewController *generalSettingsViewController = [[GeneralSettingsViewController alloc]
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    36
                                                                    initWithStyle:UITableViewStyleGrouped];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    37
    generalSettingsViewController.title = NSLocalizedString(@"General",@"");
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    38
    generalSettingsViewController.navigationItem.hidesBackButton = YES;
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    39
    [array addObject:generalSettingsViewController];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    40
    [generalSettingsViewController release];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    41
    
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    42
    TeamSettingsViewController *teamSettingsViewController = [[TeamSettingsViewController 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
    teamSettingsViewController.title = NSLocalizedString(@"Teams",@"");
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    45
    teamSettingsViewController.navigationItem.hidesBackButton = YES;
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    46
    [array addObject:teamSettingsViewController];
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    47
    [teamSettingsViewController 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
    self.controllers = array;
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    50
    [array release];
3305
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
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    54
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    57
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
#pragma mark Table view data source
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
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    62
    return 1;
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
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
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    67
    return [optionList count];
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
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
// Customize the appearance of table view cells.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    72
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    73
    static NSString *CellIdentifier = @"Cell";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    74
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    75
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    76
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    77
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    78
        cell.textLabel.text = [optionList objectAtIndex:[indexPath row]];
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
    return cell;
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
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    85
// Override to support editing the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    86
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
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
    if (editingStyle == UITableViewCellEditingStyleDelete) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    89
        // Delete the row from the data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    90
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: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
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    93
        // 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
    94
    }   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    95
}
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
// Override to support rearranging the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   100
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
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
*/
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
// Override to support conditional rearranging of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   106
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   107
    // 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
   108
    return YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   109
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   110
*/
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   113
#pragma mark Table view delegate
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   114
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   115
    int newRow = [indexPath row];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   116
    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : 0;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   117
    
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   118
    if (newRow != oldRow) {
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   119
        [detailViewController.navigationController popToRootViewControllerAnimated:NO];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   120
        
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   121
        UITableViewController *nextController = [self.controllers objectAtIndex:[indexPath row]];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   122
        [detailViewController.navigationController pushViewController:nextController animated:YES];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   123
        self.lastIndexPath = indexPath;
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   124
        [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   125
    }
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   126
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   127
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   128
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   131
#pragma mark Memory management
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   132
-(void) didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   133
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   134
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   135
    // Relinquish ownership any cached data, images, etc that aren't in use.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   138
- (void)dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   139
    [optionList release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   140
    [detailViewController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   141
    [super dealloc];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   142
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   143
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   144
-(IBAction) dismissSplitView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   145
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   146
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   147
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   148
@end
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   149