cocoaTouch/SingleTeamViewController.m
author koda
Thu, 08 Apr 2010 22:45:18 +0000
changeset 3325 652a8ebdf667
parent 3323 091cf214bdd5
child 3328 fe87c2242984
permissions -rw-r--r--
moved around team creation add flags support add forts support need to find another way to save on file
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
//  SingleTeamViewController.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 "SingleTeamViewController.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    10
#import "HogHatViewController.h"
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    11
#import "FlagsViewController.h"
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    12
#import "FortsViewController.h"
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    13
#import "CommodityFunctions.h"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    14
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    15
@implementation SingleTeamViewController
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    16
@synthesize teamDictionary, hatArray, secondaryItems, secondaryControllers;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    17
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    18
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    19
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    20
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    21
}
3305
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    24
#pragma mark View lifecycle
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    25
- (void)viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    26
    [super viewDidLoad];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    27
   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    28
    NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    29
                             NSLocalizedString(@"Grave",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    30
                             NSLocalizedString(@"Voice",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    31
                             NSLocalizedString(@"Fort",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    32
                             NSLocalizedString(@"Flag",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    33
                             NSLocalizedString(@"Level",@""),nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    34
    self.secondaryItems = array;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    35
    [array release];
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    36
    
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    37
    // insert controllers here
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    38
    NSMutableArray *controllersArray = [[NSMutableArray alloc] initWithCapacity:[secondaryItems count]];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    39
    
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    40
    FlagsViewController *flagsViewController = [[FlagsViewController alloc] initWithStyle:UITableViewStyleGrouped];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    41
    flagsViewController.teamDictionary = self.teamDictionary;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    42
    [controllersArray addObject:flagsViewController];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    43
    [flagsViewController release];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    44
    
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    45
    FortsViewController *fortsViewController = [[FortsViewController alloc] initWithStyle:UITableViewStyleGrouped];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    46
    fortsViewController.teamDictionary = self.teamDictionary;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    47
    [controllersArray addObject:fortsViewController];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    48
    [fortsViewController release];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    49
    
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    50
    self.secondaryControllers = controllersArray;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    51
    [controllersArray release];
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    52
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    53
    // listen if any childController modifies the plist and write it if needed
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    54
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setWriteNeeded) name:@"setWriteNeedTeams" object:nil];
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    55
    isWriteNeeded = NO;
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    56
}
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    57
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    58
- (void)viewWillAppear:(BOOL)animated {
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    59
    [super viewWillAppear:animated];
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3316
diff changeset
    60
    
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    61
    self.title = [self.teamDictionary objectForKey:@"teamname"];
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    62
    
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    63
    // load the images of the hat for aach hog
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    64
    NSArray *hogArray = [self.teamDictionary objectForKey:@"hedgehogs"];
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    65
    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[hogArray count]];
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    66
    for (NSDictionary *hog in hogArray) {
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    67
        NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@.png", HATS_DIRECTORY(), [hog objectForKey:@"hat"]];
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    68
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    69
        UIImage *image = [[UIImage alloc] initWithContentsOfFile: hatFile];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3315
diff changeset
    70
        [hatFile release];
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    71
        CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32);
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    72
        CGImageRef cgImgage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea);
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    73
        [image release];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    74
        
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    75
        UIImage *hatSprite = [[UIImage alloc] initWithCGImage:cgImgage];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    76
        [array addObject:hatSprite];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    77
        CGImageRelease(cgImgage);
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    78
        [hatSprite release];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    79
    }
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    80
    self.hatArray = array;
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    81
    [array release];
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    82
    
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    83
    [self.tableView reloadData];
3305
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
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    86
// needed by other classes to warn about a user change
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    87
-(void) setWriteNeeded {
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    88
    isWriteNeeded = YES;
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    89
}
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    90
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    91
// write to disk the team dictionary
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    92
-(void) viewWillDisappear:(BOOL)animated {
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    93
    [super viewWillDisappear:animated];
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    94
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    95
    if (isWriteNeeded) {
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    96
        NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),self.title];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    97
        [self.teamDictionary writeToFile:teamFile atomically:YES];
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    98
        [teamFile release];
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    99
        NSLog(@"writing: %@",teamDictionary);
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   100
        isWriteNeeded = NO;
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   101
    }
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   102
}
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   103
3305
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   106
#pragma mark Table view data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   107
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   108
    return 3;
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
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   112
    NSInteger rows = 0;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   113
    switch (section) {
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   114
        case 0: // team name
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   115
            rows = 1;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
            break;
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   117
        case 1: // team members
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   118
            rows = MAX_HOGS;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
            break;
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   120
        case 2: // team details
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   121
            rows = [self.secondaryItems count];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   122
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   123
        default:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   124
            break;
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
    return rows;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   129
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   130
    static NSString *CellIdentifier = @"Cell";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   131
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   132
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   133
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   134
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   135
                                       reuseIdentifier:CellIdentifier] autorelease];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
    }
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   137
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   138
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   139
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   140
    NSArray *hogArray;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   141
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   142
    switch ([indexPath section]) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   143
        case 0:
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   144
            cell.textLabel.text = self.title;
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   145
            cell.imageView.image = nil;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   146
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   147
        case 1:
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   148
            hogArray = [self.teamDictionary objectForKey:@"hedgehogs"];
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   149
            cell.textLabel.text = [[hogArray objectAtIndex:row] objectForKey:@"hogname"];
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   150
            cell.imageView.image = [self.hatArray objectAtIndex:row];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   151
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   152
        case 2:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   153
            cell.textLabel.text = [self.secondaryItems objectAtIndex:row];
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   154
            switch (row) {
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   155
                case 3: // flags
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   156
                    cell.imageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png",
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   157
                                                                             FLAGS_DIRECTORY(),[teamDictionary objectForKey:@"flag"]]];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   158
                    break;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   159
                default:
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   160
                    cell.imageView.image = nil;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   161
                    break;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   162
            }
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   163
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   164
        default:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   165
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   166
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   167
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   168
    return cell;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   169
}
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
// Override to support conditional editing of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   174
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   175
    // Return NO if you do not want the specified item to be editable.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   176
    return YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   177
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   178
*/
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
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   182
// Override to support editing the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   183
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   184
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   185
    if (editingStyle == UITableViewCellEditingStyleDelete) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   186
        // Delete the row from the data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   187
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   188
    }   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   189
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   190
        // 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
   191
    }   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   192
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   193
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   194
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   195
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
// Override to support rearranging the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   198
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   199
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   200
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   201
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   202
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   203
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   204
// Override to support conditional rearranging of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   205
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   206
    // 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
   207
    return YES;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   211
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   212
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   213
#pragma mark Table view delegate
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   214
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   215
    NSInteger row = [indexPath row];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   216
    UITableViewController *nextController;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   217
    if (1 == [indexPath section]) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   218
        if (nil == hogChildController) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   219
            hogChildController = [[HogHatViewController alloc] initWithStyle:UITableViewStyleGrouped];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   220
        }
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   221
        
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   222
        // cache the dictionary file of the team, so that other controllers can modify it
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   223
        hogChildController.teamDictionary = self.teamDictionary;
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   224
        hogChildController.selectedHog = row;
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   225
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   226
        nextController = hogChildController;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   227
    }
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   228
    if (2 == [indexPath section]) {
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   229
        //TODO: this part should be rewrittend with lazy loading instead of an array of controllers
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   230
        nextController = [secondaryControllers objectAtIndex:row%2 ];              //TODO: fix the objectAtIndex
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   231
        nextController.title = [secondaryItems objectAtIndex:row];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   232
    }
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   233
    [self.navigationController pushViewController:nextController animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   234
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   235
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   236
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   237
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   238
#pragma mark Memory management
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   239
-(void) didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   240
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   241
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   242
    // Relinquish ownership any cached data, images, etc that aren't in use.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   243
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   244
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   245
-(void) viewDidUnload {
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   246
    self.secondaryControllers = nil;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   247
    self.secondaryItems = nil;
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   248
    self.hatArray = nil;
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   249
    self.teamDictionary = nil;
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   250
    [super viewDidUnload];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   251
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   252
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   253
-(void) dealloc {
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   254
    [secondaryControllers release];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   255
    [secondaryItems release];
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   256
    [hatArray release];
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   257
    [teamDictionary release];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   258
    [super dealloc];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   259
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   260
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   261
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   262
@end
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   263