cocoaTouch/DetailViewController.m
author koda
Sun, 04 Apr 2010 19:51:53 +0000
changeset 3305 91074496d5c9
child 3308 b6dcae4b6d2c
permissions -rw-r--r--
merged code from ipad and iphone frontends (aka HedgewarsMobile is a universal application)
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",@"");
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    28
    [array addObject:teamSettingsViewController];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    29
    [teamSettingsViewController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    30
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    31
    self.controllers = array;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    32
    [array release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    33
        
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    34
    [super viewDidLoad];
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    37
- (void)didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    38
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    39
    [super didReceiveMemoryWarning];
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
    // Release any cached data, images, etc that aren't in use.
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)viewDidUnload {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    45
    self.controllers = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    46
    self.popoverController = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    47
    [super viewDidUnload];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    48
}
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
- (void)dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    51
    [controllers release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    52
    [popoverController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    53
    [super dealloc];
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    57
#pragma mark Table view data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
    return 1;
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
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    63
    return [controllers count];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
}
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 *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    67
    static NSString *CellIdentifier = @"Cell";
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
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    70
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    71
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    72
                                       reuseIdentifier:CellIdentifier] autorelease];
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 row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    76
    UITableViewController *controller = [controllers objectAtIndex:row];
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
    cell.textLabel.text = controller.title;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    79
    cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    80
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
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
    return cell;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    85
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    86
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    87
    UITableViewController *nextController = [self.controllers objectAtIndex:row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    88
    [self.navigationController pushViewController:nextController animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    89
}
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    93
#pragma mark Managing the popover controller
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    94
// 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
    95
-(void) setDetailItem:(id) newDetailItem {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    96
    if (detailItem != newDetailItem) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    97
        [detailItem release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    98
        detailItem = [newDetailItem retain];
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
        // Update the view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   101
       // navigationBar.topItem.title = (NSString*) detailItem;
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
		//test.text=(NSString*) detailItem;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   106
  //  if (popoverController != nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   107
  //      [popoverController dismissPopoverAnimated:YES];
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
*/
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   113
#pragma mark Split view support
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   114
#ifdef __IPHONE_3_2
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   115
-(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
   116
    barButtonItem.title = @"Master List";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   117
  //  [navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   118
    self.popoverController = pc;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
}
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
// 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
   122
-(void) splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   123
  //  [navigationBar.topItem setLeftBarButtonItem:nil animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   124
    self.popoverController = nil;
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
#endif
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   127
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   128
#pragma mark Rotation support
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   129
// 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
   130
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   131
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
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
-(IBAction) dismissSplitView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   135
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
}
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
@end