cocoaTouch/TeamSettingsViewController.m
author smxx
Thu, 08 Apr 2010 17:56:30 +0000
changeset 3324 339b271d6641
parent 3323 091cf214bdd5
child 3325 652a8ebdf667
permissions -rw-r--r--
Frontend: * Show a text notice instead of settings page's (disabled) modify team buttons while in a room or game setup screen
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
//  TeamSettingsViewController.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 02/04/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 "TeamSettingsViewController.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    10
#import "SingleTeamViewController.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    11
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    12
@implementation TeamSettingsViewController
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    13
@synthesize listOfTeams;
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    14
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    15
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    16
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    17
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    18
}
3305
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    21
#pragma mark View lifecycle
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    22
- (void)viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    23
    [super viewDidLoad];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    24
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    25
    UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Edit",@"from the team navigation")
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    26
                                                                   style:UIBarButtonItemStyleBordered
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    27
                                                                  target:self
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    28
                                                                  action:@selector(toggleEdit:)];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    29
    self.navigationItem.rightBarButtonItem = editButton;
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    30
    [editButton release];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    31
    
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    32
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    33
    NSString *teamsDirectory = [[paths objectAtIndex:0] stringByAppendingString:@"/Teams/"];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    34
    
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    35
    NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:teamsDirectory error:NULL];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    36
    NSMutableArray *array = [[NSMutableArray alloc] initWithArray: contentsOfDir copyItems:YES];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    37
    self.listOfTeams = array;
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    38
    [array release];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    39
    NSLog(@"files: %@", self.listOfTeams);
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    40
}
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    41
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    42
// modifies the navigation bar to add the "Add" and "Done" buttons
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    43
-(void) toggleEdit:(id) sender {
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    44
    BOOL isEditing = self.tableView.editing;
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    45
    [self.tableView setEditing:!isEditing animated:YES];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    46
    
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    47
    if (isEditing) {
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    48
        [self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Edit",@"from the team navigation")];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    49
        [self.navigationItem.rightBarButtonItem setStyle: UIBarButtonItemStyleBordered];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    50
        self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem;
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    51
    } else {
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    52
        [self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Done",@"from the team navigation")];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    53
        [self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    54
        UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Add",@"from the team navigation")
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    55
                                                                      style:UIBarButtonItemStyleBordered
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    56
                                                                     target:self
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    57
                                                                     action:@selector(addTeam:)];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    58
        self.navigationItem.leftBarButtonItem = addButton;
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    59
        [addButton release];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    60
    }
3305
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
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    63
// add a team file with default values and updates the table
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    64
-(void) addTeam:(id) sender {
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    65
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    66
    NSString *teamsDirectory = [[paths objectAtIndex:0] stringByAppendingString:@"/Teams/"];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    67
    [[NSFileManager defaultManager] createDirectoryAtPath:teamsDirectory 
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    68
                              withIntermediateDirectories:NO 
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    69
                                               attributes:nil 
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    70
                                                    error:NULL];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    71
    
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    72
    NSMutableArray *hedgehogs = [[NSMutableArray alloc] init];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    73
    
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    74
    for (int i = 0; i < 8; i++) {
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    75
        NSString *hogName = [[NSString alloc] initWithFormat:@"hedgehog %d",i];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    76
        NSDictionary *hog = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    77
                             hogName,@"hogname",@"NoHat",@"hat",nil];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    78
        [hogName release];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    79
        [hedgehogs addObject:hog];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    80
        [hog release];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    81
    }
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    82
    
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    83
    NSString *fileName = [[NSString alloc] initWithFormat:@"Default Team %u.plist", [self.listOfTeams count]];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    84
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    85
    NSDictionary *defaultTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4421353",@"color",@"0",@"hash",
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    86
                                 [fileName stringByDeletingPathExtension],@"teamname",@"Statue",@"grave",@"Plane",@"fort",
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    87
                                 @"Default",@"voicepack",@"hedgewars",@"flag",hedgehogs,@"hedgehogs",nil];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    88
    [hedgehogs release];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    89
    
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    90
    NSString *defaultTeamFile = [[NSString alloc] initWithFormat:@"%@/%@",teamsDirectory, fileName];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    91
    [defaultTeam writeToFile:defaultTeamFile atomically:YES];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    92
    [defaultTeamFile release];    
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    93
    [defaultTeam release];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    94
    
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    95
    [self.listOfTeams addObject:fileName];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    96
    [fileName release];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    97
    
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    98
    [self.tableView reloadData];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
    99
    
3305
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   102
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   103
#pragma mark Table view data source
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   104
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   105
    // Return the number of sections.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   106
    return 1;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   107
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   108
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   109
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   110
    // Return the number of rows in the section.
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   111
    return [listOfTeams count];
3305
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   114
// Customize the appearance of table view cells.
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   115
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
    static NSString *CellIdentifier = @"Cell";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   117
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   118
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   120
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
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
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   123
    NSUInteger row = [indexPath row]; 
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   124
    NSString *rowString = [[listOfTeams objectAtIndex:row] stringByDeletingPathExtension]; 
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   125
    cell.textLabel.text = rowString; 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   126
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   127
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   128
    return cell;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   129
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   130
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   131
// delete the row and the file
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   132
-(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   133
    NSUInteger row = [indexPath row];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   134
    
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   135
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   136
    NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/Teams/%@",[paths objectAtIndex:0],[self.listOfTeams objectAtIndex:row]];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   138
    [[NSFileManager defaultManager] removeItemAtPath:teamFile error:NULL];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   139
    [teamFile release];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   140
    
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   141
    [self.listOfTeams removeObjectAtIndex:row];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   142
    [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   143
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   144
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   145
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   146
// Override to support editing the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   147
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   148
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   149
    if (editingStyle == UITableViewCellEditingStyleDelete) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   150
        // Delete the row from the data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   151
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   152
    }   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   153
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   154
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   155
    }   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   156
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   157
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   158
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   159
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   160
// Override to support rearranging the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   161
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   162
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   163
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   164
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   165
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   166
// Override to support conditional rearranging of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   167
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   168
    // Return NO if you do not want the item to be re-orderable.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   169
    return YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   170
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   171
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   172
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   173
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   174
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   175
#pragma mark Table view delegate
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   176
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   177
    if (childController == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   178
        childController = [[SingleTeamViewController alloc] initWithStyle:UITableViewStyleGrouped];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   179
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   180
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   181
    NSInteger row = [indexPath row];
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   182
    NSString *selectedTeamFile = [listOfTeams objectAtIndex:row];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   183
    NSLog(@"%@",selectedTeamFile);
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   184
    
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   185
        // load data about the team and extract info
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   186
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   187
    NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/Teams/%@",[paths objectAtIndex:0],selectedTeamFile];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   188
    NSMutableDictionary *teamDict = [[NSMutableDictionary alloc] initWithContentsOfFile:teamFile];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   189
    [teamFile release];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   190
    childController.teamDictionary = teamDict;
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   191
    [teamDict release];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   192
    
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   193
    // this must be set so childController can load the correct plist
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   194
    //childController.title = [[listOfTeams objectAtIndex:row] stringByDeletingPathExtension];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   195
    [self.navigationController pushViewController:childController animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   196
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   197
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   198
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   199
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   200
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Hey, do you see the disclosure button?" 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   201
                                                    message:@"If you're trying to drill down, touch that instead" 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   202
                                                   delegate:nil
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   203
                                          cancelButtonTitle:@"Won't happen again"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   204
                                          otherButtonTitles:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   205
    [alert show];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   206
    [alert release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   207
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   208
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   209
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   210
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   211
#pragma mark Memory management
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   212
-(void) didReceiveMemoryWarning {
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   213
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   214
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   215
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   216
    // Relinquish ownership any cached data, images, etc that aren't in use.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   217
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   218
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   219
-(void) viewDidUnload {
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   220
    self.listOfTeams = nil;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   221
}
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3308
diff changeset
   222
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   223
-(void) dealloc {
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   224
    [listOfTeams release];
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3315
diff changeset
   225
    [childController release];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   226
    [super dealloc];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   227
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   228
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   229
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   230
@end
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   231