cocoaTouch/DetailViewController.m
author koda
Wed, 07 Apr 2010 01:22:05 +0000
changeset 3316 52f0482b043f
parent 3312 6d8f1c76756d
child 3335 2520ee7a5484
permissions -rw-r--r--
fix a couple of leaks in hte ifrontend
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
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    21
    // allocate controllers and store them into the array
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    22
    NSMutableArray *array= [[NSMutableArray alloc] init];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    23
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    24
    GeneralSettingsViewController *generalSettingsViewController = [[GeneralSettingsViewController alloc]
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    25
                                                                    initWithStyle:UITableViewStyleGrouped];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    26
    generalSettingsViewController.title = NSLocalizedString(@"General",@"");
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    27
    [array addObject:generalSettingsViewController];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    28
    [generalSettingsViewController release];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    29
    
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    30
    TeamSettingsViewController *teamSettingsViewController = [[TeamSettingsViewController alloc] 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    31
                                                              initWithStyle:UITableViewStyleGrouped];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    32
    teamSettingsViewController.title = NSLocalizedString(@"Teams",@"");
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    33
    [array addObject:teamSettingsViewController];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    34
    [teamSettingsViewController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    35
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    36
    self.controllers = array;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    37
    [array release];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    38
    
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    39
    // 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
    40
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    41
        UITableViewController *nextController = [self.controllers objectAtIndex:0];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    42
        nextController.navigationItem.hidesBackButton = YES;
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    43
        [self.navigationController pushViewController:nextController animated:NO];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    44
    } else {
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    45
        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
    46
    }
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    47
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    48
    [super viewDidLoad];
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)didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    52
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    53
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    54
    // Release any cached data, images, etc that aren't in use.
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)viewDidUnload {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
    self.controllers = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
    self.popoverController = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    60
    [super viewDidUnload];
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
- (void)dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
    [controllers release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    65
    [popoverController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    66
    [super dealloc];
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    70
#pragma mark Table view data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    71
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    72
    return 1;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    75
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    76
    return [controllers count];
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    79
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    80
    static NSString *CellIdentifier = @"Cell";
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
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    83
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    84
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    85
                                       reuseIdentifier:CellIdentifier] autorelease];
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
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    88
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    89
    UITableViewController *controller = [controllers objectAtIndex:row];
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
    cell.textLabel.text = controller.title;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    92
    cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    93
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
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
    return cell;
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
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    99
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   100
    UITableViewController *nextController = [self.controllers objectAtIndex:row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   101
    [self.navigationController pushViewController:nextController animated:YES];
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   106
#pragma mark Managing the popover controller
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   107
// 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
   108
-(void) setDetailItem:(id) newDetailItem {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   109
    if (detailItem != newDetailItem) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   110
        [detailItem release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   111
        detailItem = [newDetailItem retain];
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
        // Update the view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   114
       // navigationBar.topItem.title = (NSString*) detailItem;
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
		//test.text=(NSString*) detailItem;
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
  //  if (popoverController != nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   120
  //      [popoverController dismissPopoverAnimated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   121
  //  }        
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   125
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   126
#pragma mark Split view support
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   127
#ifdef __IPHONE_3_2
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   128
-(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
   129
    barButtonItem.title = @"Master List";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   130
  //  [navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   131
    self.popoverController = pc;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   134
// 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
   135
-(void) splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
  //  [navigationBar.topItem setLeftBarButtonItem:nil animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
    self.popoverController = nil;
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
#endif
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   140
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   141
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   142
#pragma mark Rotation support
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   143
// 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
   144
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   145
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
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
-(IBAction) dismissSplitView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   149
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   150
}
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
@end