cocoaTouch/DetailViewController.m
author koda
Tue, 06 Apr 2010 21:54:46 +0000
changeset 3315 4e2813713358
parent 3312 6d8f1c76756d
child 3316 52f0482b043f
permissions -rw-r--r--
usa a cached dictionary and write only when needed
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"
3305
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 DetailViewController
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    15
@synthesize popoverController, controllers;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    18
- (void)viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    19
    self.title = NSLocalizedString(@"Settings",@"");
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
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    22
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:0 target:self action:@selector(dismissSplitView)];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    23
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    24
    NSMutableArray *array= [[NSMutableArray alloc] init];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    25
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    26
    GeneralSettingsViewController *generalSettingsViewController = [[GeneralSettingsViewController alloc]
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    27
                                                                    initWithStyle:UITableViewStyleGrouped];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    28
    generalSettingsViewController.title = NSLocalizedString(@"General",@"");
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    29
    [array addObject:generalSettingsViewController];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    30
    [generalSettingsViewController release];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    31
    
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    32
    TeamSettingsViewController *teamSettingsViewController = [[TeamSettingsViewController alloc] 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    33
                                                              initWithStyle:UITableViewStyleGrouped];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    34
    teamSettingsViewController.title = NSLocalizedString(@"Teams",@"");
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    35
    [array addObject:teamSettingsViewController];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    36
    [teamSettingsViewController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    37
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    38
    self.controllers = array;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    39
    [array 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
    [super viewDidLoad];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    42
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    43
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    44
- (void)didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    45
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    46
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    47
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    48
    // Release any cached data, images, etc that aren't in use.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    49
}
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
- (void)viewDidUnload {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    52
    self.controllers = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    53
    self.popoverController = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    54
    [super viewDidUnload];
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
- (void)dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
    [controllers release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
    [popoverController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    60
    [super dealloc];
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
#pragma mark Table view data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    65
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    66
    return 1;
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 [controllers 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
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    74
    static NSString *CellIdentifier = @"Cell";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    75
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    76
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    77
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    78
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    79
                                       reuseIdentifier:CellIdentifier] autorelease];
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
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    82
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    83
    UITableViewController *controller = [controllers objectAtIndex:row];
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
    cell.textLabel.text = controller.title;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    86
    cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    87
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    88
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    89
    return cell;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    92
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
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 *nextController = [self.controllers objectAtIndex:row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    95
    [self.navigationController pushViewController:nextController animated:YES];
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   100
#pragma mark Managing the popover controller
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   101
// 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
   102
-(void) setDetailItem:(id) newDetailItem {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   103
    if (detailItem != newDetailItem) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   104
        [detailItem release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   105
        detailItem = [newDetailItem retain];
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
        // Update the view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   108
       // navigationBar.topItem.title = (NSString*) detailItem;
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
		//test.text=(NSString*) detailItem;
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
  //  if (popoverController != nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   114
  //      [popoverController dismissPopoverAnimated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   115
  //  }        
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
}
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   120
#pragma mark Split view support
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   121
#ifdef __IPHONE_3_2
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   122
-(void) splitViewController:(UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   123
    barButtonItem.title = @"Master List";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   124
  //  [navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   125
    self.popoverController = pc;
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
// 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
   129
-(void) splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   130
  //  [navigationBar.topItem setLeftBarButtonItem:nil animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   131
    self.popoverController = nil;
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
#endif
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   134
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   135
#pragma mark Rotation support
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
// Ensure that the view controller supports rotation and that the split view can therefore show in both portrait and landscape.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   138
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   141
-(IBAction) dismissSplitView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   142
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object: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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   145
@end