cocoaTouch/DetailViewController.m
author koda
Tue, 06 Apr 2010 02:39:06 +0000
changeset 3308 b6dcae4b6d2c
parent 3305 91074496d5c9
child 3312 6d8f1c76756d
permissions -rw-r--r--
make the tables work also on iphone make the popover menu work also on iphone
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"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    10
#import "TeamSettingsViewController.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    11
#import "SDL_uikitappdelegate.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    12
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    13
@implementation DetailViewController
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    14
@synthesize popoverController, controllers;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    15
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
- (void)viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    18
    self.title = NSLocalizedString(@"Settings",@"");
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
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    21
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:0 target:self action:@selector(dismissSplitView)];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    22
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    23
    NSMutableArray *array= [[NSMutableArray alloc] init];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    24
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    25
    TeamSettingsViewController *teamSettingsViewController = [[TeamSettingsViewController alloc] 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    26
                                                              initWithStyle:UITableViewStyleGrouped];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    27
    teamSettingsViewController.title = NSLocalizedString(@"Teams",@"");
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    28
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    29
    [array addObject:teamSettingsViewController];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    30
    [teamSettingsViewController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    31
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    32
    self.controllers = array;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    33
    [array release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    34
        
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    35
    [super viewDidLoad];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    36
}
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
- (void)didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    39
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    40
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    41
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    42
    // Release any cached data, images, etc that aren't in use.
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    45
- (void)viewDidUnload {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    46
    self.controllers = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    47
    self.popoverController = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    48
    [super viewDidUnload];
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)dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    52
    [controllers release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    53
    [popoverController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    54
    [super dealloc];
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
#pragma mark Table view data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    60
    return 1;
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
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
    return [controllers count];
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    67
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    68
    static NSString *CellIdentifier = @"Cell";
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
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    71
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    72
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    73
                                       reuseIdentifier:CellIdentifier] autorelease];
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
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    76
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    77
    UITableViewController *controller = [controllers objectAtIndex:row];
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
    cell.textLabel.text = controller.title;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    80
    cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    81
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
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
    return cell;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    86
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    87
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    88
    UITableViewController *nextController = [self.controllers objectAtIndex:row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    89
    [self.navigationController pushViewController:nextController animated:YES];
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
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    93
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    94
#pragma mark Managing the popover controller
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    95
// 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
    96
-(void) setDetailItem:(id) newDetailItem {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    97
    if (detailItem != newDetailItem) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    98
        [detailItem release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    99
        detailItem = [newDetailItem retain];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   100
        
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   101
        // Update the view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   102
       // navigationBar.topItem.title = (NSString*) detailItem;
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
		//test.text=(NSString*) detailItem;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   105
    }
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
  //  if (popoverController != nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   108
  //      [popoverController dismissPopoverAnimated: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
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 Split view support
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   115
#ifdef __IPHONE_3_2
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
-(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
   117
    barButtonItem.title = @"Master List";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   118
  //  [navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
    self.popoverController = pc;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   122
// 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
   123
-(void) splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   124
  //  [navigationBar.topItem setLeftBarButtonItem:nil animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   125
    self.popoverController = nil;
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
#endif
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   128
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   129
#pragma mark Rotation support
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   130
// 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
   131
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   132
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   135
-(IBAction) dismissSplitView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
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
@end