cocoaTouch/TeamConfigViewController.m
changeset 3361 cfc6cd502f85
child 3364 e5403e2bf02c
equal deleted inserted replaced
3360:717b4e46e855 3361:cfc6cd502f85
       
     1 //
       
     2 //  TeamConfigViewController.m
       
     3 //  HedgewarsMobile
       
     4 //
       
     5 //  Created by Vittorio on 20/04/10.
       
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
       
     7 //
       
     8 
       
     9 #import "TeamConfigViewController.h"
       
    10 #import "CommodityFunctions.h"
       
    11 #import "HogButtonView.h"
       
    12 #import "SquareButtonView.h"
       
    13 
       
    14 @implementation TeamConfigViewController
       
    15 @synthesize listOfTeams;
       
    16 
       
    17 #define NUMBERBUTTON_TAG 123456
       
    18 #define SQUAREBUTTON_TAG 654321
       
    19 
       
    20 #pragma mark -
       
    21 #pragma mark View lifecycle
       
    22 -(void) viewDidLoad {
       
    23     [super viewDidLoad];
       
    24     
       
    25     CGSize screenSize = [[UIScreen mainScreen] bounds].size;
       
    26     self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44);
       
    27 }
       
    28 
       
    29 
       
    30 
       
    31 -(void) viewWillAppear:(BOOL)animated {
       
    32     [super viewWillAppear:animated];
       
    33 
       
    34     NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL];
       
    35     NSMutableArray *array = [[NSMutableArray alloc] initWithArray:contentsOfDir copyItems:YES];
       
    36     self.listOfTeams = array;
       
    37     [array release];
       
    38     
       
    39     [self.tableView reloadData];
       
    40     NSLog(@"%@",listOfTeams);
       
    41 }
       
    42 
       
    43 /*
       
    44 - (void)viewDidAppear:(BOOL)animated {
       
    45     [super viewDidAppear:animated];
       
    46 }
       
    47 */
       
    48 /*
       
    49 - (void)viewWillDisappear:(BOOL)animated {
       
    50     [super viewWillDisappear:animated];
       
    51 }
       
    52 */
       
    53 /*
       
    54 - (void)viewDidDisappear:(BOOL)animated {
       
    55     [super viewDidDisappear:animated];
       
    56 }
       
    57 */
       
    58 
       
    59 
       
    60 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
       
    61     return rotationManager(interfaceOrientation);
       
    62 }
       
    63 
       
    64 
       
    65 #pragma mark -
       
    66 #pragma mark Table view data source
       
    67 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
       
    68     return 1;
       
    69 }
       
    70 
       
    71 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
       
    72     return [listOfTeams count];
       
    73 }
       
    74 
       
    75 
       
    76 // Customize the appearance of table view cells.
       
    77 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
       
    78     static NSString *CellIdentifier = @"Cell";
       
    79     
       
    80     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
       
    81     if (cell == nil) {
       
    82         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
       
    83         
       
    84         UIButton *numberButton = [[HogButtonView alloc] initWithFrame:CGRectMake(12, 5, 88, 32)];
       
    85         numberButton.tag = NUMBERBUTTON_TAG;
       
    86         [cell addSubview:numberButton];
       
    87         [numberButton release];
       
    88         
       
    89         SquareButtonView *squareButton = [[SquareButtonView alloc] initWithFrame:CGRectMake(12+88+7, 5, 36, 36)];
       
    90         squareButton.tag = SQUAREBUTTON_TAG;
       
    91         [cell addSubview:squareButton];
       
    92         [squareButton release];
       
    93     }
       
    94     
       
    95     cell.textLabel.text = [[listOfTeams objectAtIndex:[indexPath row]] stringByDeletingPathExtension];
       
    96     
       
    97     return cell;
       
    98 }
       
    99 
       
   100 
       
   101 /*
       
   102 // Override to support conditional editing of the table view.
       
   103 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
       
   104     // Return NO if you do not want the specified item to be editable.
       
   105     return YES;
       
   106 }
       
   107 */
       
   108 
       
   109 
       
   110 /*
       
   111 // Override to support editing the table view.
       
   112 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
       
   113     
       
   114     if (editingStyle == UITableViewCellEditingStyleDelete) {
       
   115         // Delete the row from the data source
       
   116         [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
       
   117     }   
       
   118     else if (editingStyle == UITableViewCellEditingStyleInsert) {
       
   119         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
       
   120     }   
       
   121 }
       
   122 */
       
   123 
       
   124 
       
   125 /*
       
   126 // Override to support rearranging the table view.
       
   127 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
       
   128 }
       
   129 */
       
   130 
       
   131 
       
   132 /*
       
   133 // Override to support conditional rearranging of the table view.
       
   134 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
       
   135     // Return NO if you do not want the item to be re-orderable.
       
   136     return YES;
       
   137 }
       
   138 */
       
   139 
       
   140 
       
   141 #pragma mark -
       
   142 #pragma mark Table view delegate
       
   143 
       
   144 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
       
   145     // Navigation logic may go here. Create and push another view controller.
       
   146 	/*
       
   147 	 <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
       
   148      // ...
       
   149      // Pass the selected object to the new view controller.
       
   150 	 [self.navigationController pushViewController:detailViewController animated:YES];
       
   151 	 [detailViewController release];
       
   152 	 */
       
   153 }
       
   154 
       
   155 
       
   156 #pragma mark -
       
   157 #pragma mark Memory management
       
   158 
       
   159 -(void) didReceiveMemoryWarning {
       
   160     // Releases the view if it doesn't have a superview.
       
   161     [super didReceiveMemoryWarning];
       
   162     // Relinquish ownership any cached data, images, etc that aren't in use.
       
   163 }
       
   164 
       
   165 -(void) viewDidUnload {
       
   166     self.listOfTeams = nil;
       
   167 }
       
   168 
       
   169 
       
   170 -(void) dealloc {
       
   171     [listOfTeams release];
       
   172     [super dealloc];
       
   173 }
       
   174 
       
   175 
       
   176 @end
       
   177