cocoaTouch/DetailViewController.m
author koda
Tue, 13 Apr 2010 22:45:46 +0000
changeset 3340 96dd168b080b
parent 3335 2520ee7a5484
child 3356 3ae3fccb439e
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
//  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"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    11
#import "TeamSettingsViewController.h"
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    12
#import "GeneralSettingsViewController.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 DetailViewController
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    16
@synthesize popoverController, controllers;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    17
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    18
3335
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
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    23
- (void)viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    24
    self.title = NSLocalizedString(@"Settings",@"");
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    25
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    26
    // allocate controllers and store them into the array
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    27
    NSMutableArray *array= [[NSMutableArray alloc] init];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    28
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    29
    GeneralSettingsViewController *generalSettingsViewController = [[GeneralSettingsViewController alloc]
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    30
                                                                    initWithStyle:UITableViewStyleGrouped];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    31
    generalSettingsViewController.title = NSLocalizedString(@"General",@"");
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    32
    [array addObject:generalSettingsViewController];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    33
    [generalSettingsViewController release];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    34
    
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    35
    TeamSettingsViewController *teamSettingsViewController = [[TeamSettingsViewController alloc] 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    36
                                                              initWithStyle:UITableViewStyleGrouped];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    37
    teamSettingsViewController.title = NSLocalizedString(@"Teams",@"");
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    38
    [array addObject:teamSettingsViewController];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    39
    [teamSettingsViewController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    40
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    41
    self.controllers = array;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    42
    [array release];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    43
    
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    44
    // 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
    45
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    46
        UITableViewController *nextController = [self.controllers objectAtIndex:0];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    47
        nextController.navigationItem.hidesBackButton = YES;
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    48
        [self.navigationController pushViewController:nextController animated:NO];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    49
    } else {
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    50
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:0 target:self action:@selector(dismissSplitView)];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    51
    }
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    52
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    53
    [super viewDidLoad];
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
- (void)didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    57
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
    // Release any cached data, images, etc that aren't in use.
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    62
- (void)viewDidUnload {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    63
    self.controllers = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
    self.popoverController = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    65
    [super viewDidUnload];
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
- (void)dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    69
    [controllers release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    70
    [popoverController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    71
    [super dealloc];
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    75
#pragma mark Table view data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    76
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    77
    return 1;
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
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    81
    return [controllers count];
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
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    85
    static NSString *CellIdentifier = @"Cell";
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
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    88
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    89
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    90
                                       reuseIdentifier:CellIdentifier] autorelease];
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
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    94
    UITableViewController *controller = [controllers objectAtIndex:row];
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
    cell.textLabel.text = controller.title;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    97
    cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    98
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
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
    return cell;
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
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   104
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   105
    UITableViewController *nextController = [self.controllers objectAtIndex:row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   106
    [self.navigationController pushViewController:nextController animated:YES];
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
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   111
#pragma mark Managing the popover controller
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   112
// 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
   113
-(void) setDetailItem:(id) newDetailItem {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   114
    if (detailItem != newDetailItem) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   115
        [detailItem release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
        detailItem = [newDetailItem retain];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   117
        
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   118
        // Update the view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
       // navigationBar.topItem.title = (NSString*) detailItem;
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
		//test.text=(NSString*) detailItem;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   124
  //  if (popoverController != nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   125
  //      [popoverController dismissPopoverAnimated:YES];
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
}
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 Split view support
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   132
#ifdef __IPHONE_3_2
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
   133
-(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
   134
    barButtonItem.title = @"Master List";
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
   135
    [self.navigationController.navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
    self.popoverController = pc;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   139
// 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
   140
-(void) splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
   141
    [self.navigationController.navigationBar.topItem setLeftBarButtonItem:nil animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   142
    self.popoverController = nil;
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
#endif
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   145
3305
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