cocoaTouch/iPad/MasterViewController.m
author palewolf
Sun, 28 Mar 2010 00:46:34 +0000
changeset 3132 72ad441d4c2f
parent 3113 2829ea0dd47c
child 3165 3ec07a7d8456
permissions -rw-r--r--
Add background color to translucent png to avoid gray borders when zooming
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3113
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     1
//
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     2
//  MasterViewController.m
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     3
//  HedgewarsMobile
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     4
//
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     5
//  Created by Vittorio on 27/03/10.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     7
//
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     8
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
     9
#import "MasterViewController.h"
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    10
#import "DetailViewController.h"
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    11
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    12
@implementation MasterViewController
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    13
@synthesize detailViewController, optionList;
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    14
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    15
#pragma mark -
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    16
#pragma mark View lifecycle
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    17
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    18
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    19
- (void)viewDidLoad {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    20
    [super viewDidLoad];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    21
    optionList = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""),
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    22
                                                  NSLocalizedString(@"Teams",@""),
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    23
                                                  NSLocalizedString(@"Weapons",@""),
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    24
                                                  NSLocalizedString(@"Schemes",@""),
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    25
                                                  nil];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    26
    
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    27
    // Uncomment the following line to preserve selection between presentations.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    28
    //self.clearsSelectionOnViewWillAppear = NO;
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    29
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    30
    //self.navigationItem.rightBarButtonItem = self.editButtonItem;
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    31
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    32
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    33
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    34
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    35
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    36
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    37
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    38
#pragma mark -
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    39
#pragma mark Table view data source
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    40
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    41
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    42
    return 1;
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    43
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    44
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    45
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    46
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    47
    return [optionList count];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    48
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    49
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    50
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    51
// Customize the appearance of table view cells.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    52
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    53
    
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    54
    static NSString *CellIdentifier = @"Cell";
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    55
    
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    56
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    57
    if (cell == nil) {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    58
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    59
        cell.textLabel.text = [optionList objectAtIndex:[indexPath row]];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    60
    }
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    61
    
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    62
    return cell;
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    63
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    64
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    65
/*
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    66
// Override to support editing the table view.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    67
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    68
    
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    69
    if (editingStyle == UITableViewCellEditingStyleDelete) {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    70
        // Delete the row from the data source
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    71
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    72
    }   
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    73
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    74
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    75
    }   
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    76
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    77
*/
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    78
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    79
/*
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    80
// Override to support rearranging the table view.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    81
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    82
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    83
*/
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    84
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    85
/*
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    86
// Override to support conditional rearranging of the table view.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    87
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    88
    // Return NO if you do not want the item to be re-orderable.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    89
    return YES;
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    90
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    91
*/
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    92
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    93
#pragma mark -
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    94
#pragma mark Table view delegate
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    95
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    96
    // Navigation logic may go here. Create and push another view controller.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    97
	/*
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    98
	 <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
    99
     // ...
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   100
     // Pass the selected object to the new view controller.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   101
	 [self.navigationController pushViewController:detailViewController animated:YES];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   102
	 [detailViewController release];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   103
	 */
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   104
    detailViewController.detailItem = [[NSString alloc] initWithFormat:@"%d", [indexPath row]];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   105
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   106
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   107
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   108
#pragma mark -
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   109
#pragma mark Memory management
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   110
-(void) didReceiveMemoryWarning {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   111
    // Releases the view if it doesn't have a superview.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   112
    [super didReceiveMemoryWarning];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   113
    
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   114
    // Relinquish ownership any cached data, images, etc that aren't in use.
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   115
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   116
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   117
- (void)dealloc {
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   118
    [optionList release];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   119
    [detailViewController release];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   120
    [super dealloc];
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   121
}
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   122
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   123
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   124
@end
2829ea0dd47c * port fadeout to opengles
koda
parents:
diff changeset
   125