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