cocoaTouch/DetailViewController.m
author koda
Sun, 18 Apr 2010 23:19:15 +0000
changeset 3356 3ae3fccb439e
parent 3335 2520ee7a5484
child 3357 3836a31879e7
permissions -rw-r--r--
add missing controller stubs initial work for the game configuration in the ifrontend stuff for working with official apple certificates use lazy loading whenever possible
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
//  DetailViewController.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 "DetailViewController.h"
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    10
#import "SDL_uikitappdelegate.h"
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    11
#import "GeneralSettingsViewController.h"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    12
#import "TeamSettingsViewController.h"
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    13
#import "WeaponSettingsViewController.h"
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    14
#import "SchemeSettingsViewController.h"
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    15
#import "CommodityFunctions.h"
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
@implementation DetailViewController
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    18
@synthesize popoverController, controllerNames;
3305
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
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    21
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    22
	return rotationManager(interfaceOrientation);
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    23
}
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    24
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    25
- (void)viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    26
    self.title = NSLocalizedString(@"Settings",@"");
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    27
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    28
    // allocate controllers and store them into the array
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    29
    NSArray *array= [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), 
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    30
                                                     NSLocalizedString(@"Teams",@""),
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    31
                                                     NSLocalizedString(@"Weapons",@""),
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    32
                                                     NSLocalizedString(@"Schemes",@""),
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    33
                                                     nil];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    34
    self.controllerNames = array;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    35
    [array release];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    36
    
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    37
    // on ipad make the general setting the first view, on iphone add the "Done" button on top left
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    38
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    39
        
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    40
        // show some stuff
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    41
        
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    42
        //[self.navigationController pushViewController:nextController animated:NO];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    43
    } else {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    44
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    45
                                                                                              target:self
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    46
                                                                                              action:@selector(dismissSplitView)];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    47
    }
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    48
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    49
    [super viewDidLoad];
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    54
#pragma mark Table view data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    55
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    56
    return 1;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    60
    return [controllerNames count];
3305
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
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
    static NSString *CellIdentifier = @"Cell";
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
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    67
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    68
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    69
                                       reuseIdentifier:CellIdentifier] autorelease];
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
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    73
    
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    74
    cell.textLabel.text = [controllerNames objectAtIndex:row];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    75
    cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    76
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
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
    return cell;
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
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    82
    NSInteger row = [indexPath row];
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    83
    UIViewController *nextController;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    84
    
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    85
    switch (row) {
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    86
        case 0:
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    87
            if (nil == generalSettingsViewController)
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    88
                generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    89
            nextController = generalSettingsViewController;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    90
            break;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    91
        case 1:
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    92
            if (nil == teamSettingsViewController)
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    93
                teamSettingsViewController = [[TeamSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    94
            nextController = teamSettingsViewController;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    95
            break;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    96
        case 2:
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    97
            if (nil == weaponSettingsViewController)
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    98
                weaponSettingsViewController = [[WeaponSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    99
            nextController = weaponSettingsViewController;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   100
            break;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   101
        case 3:
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   102
            if (nil == schemeSettingsViewController)
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   103
                schemeSettingsViewController = [[SchemeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   104
            nextController = schemeSettingsViewController;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   105
            break;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   106
    }
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   107
    
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   108
    nextController.title = [controllerNames objectAtIndex:row];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   109
    [self.navigationController pushViewController:nextController animated:YES];
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
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   113
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   114
#pragma mark Managing the popover controller
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   115
// When setting the detail item, update the view and dismiss the popover controller if it's showing.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
-(void) setDetailItem:(id) newDetailItem {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   117
    if (detailItem != newDetailItem) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   118
        [detailItem release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
        detailItem = [newDetailItem retain];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   120
        
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   121
        // Update the view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   122
       // navigationBar.topItem.title = (NSString*) detailItem;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   123
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   124
		//test.text=(NSString*) detailItem;
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
  //  if (popoverController != nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   128
  //      [popoverController dismissPopoverAnimated:YES];
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   133
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   134
#pragma mark Split view support
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   135
#ifdef __IPHONE_3_2
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
   136
-(void) splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc {
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
    barButtonItem.title = @"Master List";
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
   138
    [self.navigationController.navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   139
    self.popoverController = pc;
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
// Called when the view is shown again in the split view, invalidating the button and popover controller.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   143
-(void) splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
   144
    [self.navigationController.navigationBar.topItem setLeftBarButtonItem:nil animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   145
    self.popoverController = 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
#endif
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   148
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   149
-(IBAction) dismissSplitView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   150
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   151
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   152
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   153
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   154
-(void) didReceiveMemoryWarning {
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   155
    // Releases the view if it doesn't have a superview.
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   156
    [super didReceiveMemoryWarning];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   157
    // Release any cached data, images, etc that aren't in use.
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   158
}
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   159
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   160
-(void) viewDidUnload {
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   161
    self.controllerNames = nil;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   162
    self.popoverController = nil;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   163
    generalSettingsViewController = nil;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   164
    teamSettingsViewController = nil;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   165
    weaponSettingsViewController = nil;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   166
    schemeSettingsViewController = nil;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   167
    [super viewDidUnload];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   168
}
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   169
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   170
-(void) dealloc {
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   171
    [controllerNames release];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   172
    [popoverController release];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   173
    [generalSettingsViewController release];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   174
    [teamSettingsViewController release];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   175
    [weaponSettingsViewController release];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   176
    [schemeSettingsViewController release];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   177
    [super dealloc];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   178
}
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   179
@end