cocoaTouch/SingleTeamViewController.m
author koda
Sat, 10 Apr 2010 20:48:09 +0000
changeset 3332 3c90a923f156
parent 3330 987ec27b6042
child 3335 2520ee7a5484
permissions -rw-r--r--
simplify the general settings and review minor stuff
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
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    15
#define TEAMNAME_TAG 1234
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    16
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    17
@implementation SingleTeamViewController
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    18
@synthesize teamDictionary, hatArray, secondaryItems, secondaryControllers, textFieldBeingEdited, teamName;
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    19
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    20
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    21
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    22
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    23
}
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    24
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    25
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    26
#pragma mark -
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    27
#pragma mark textfield methods
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    28
// return to previous table
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    29
-(void) cancel:(id) sender {
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    30
    if (textFieldBeingEdited != nil)
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    31
        [self.textFieldBeingEdited resignFirstResponder];
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    32
}
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    33
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    34
// set the new value
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    35
-(BOOL) save:(id) sender {
3332
3c90a923f156 simplify the general settings and review minor stuff
koda
parents: 3330
diff changeset
    36
    NSInteger index = textFieldBeingEdited.tag;
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    37
    if (textFieldBeingEdited != nil) {
3332
3c90a923f156 simplify the general settings and review minor stuff
koda
parents: 3330
diff changeset
    38
        if (TEAMNAME_TAG == index) {
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    39
            NSLog(@"%@", textFieldBeingEdited.text);
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    40
            [self.teamDictionary setObject:textFieldBeingEdited.text forKey:@"teamname"];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    41
        } else {
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    42
            //replace the old value with the new one
3332
3c90a923f156 simplify the general settings and review minor stuff
koda
parents: 3330
diff changeset
    43
            NSDictionary *oldHog = [[teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:index];
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    44
            NSMutableDictionary *newHog = [[NSMutableDictionary alloc] initWithDictionary: oldHog];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    45
            [newHog setObject:textFieldBeingEdited.text forKey:@"hogname"];
3332
3c90a923f156 simplify the general settings and review minor stuff
koda
parents: 3330
diff changeset
    46
            [[teamDictionary objectForKey:@"hedgehogs"] replaceObjectAtIndex:index withObject:newHog];
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    47
            [newHog release];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    48
        }
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    49
        
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    50
        isWriteNeeded = YES;
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    51
        [self.textFieldBeingEdited resignFirstResponder];
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    52
        return YES;
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    53
    }
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    54
    return NO;
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    55
}
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    56
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    57
// the textfield is being modified, update the navigation controller
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    58
-(void) textFieldDidBeginEditing:(UITextField *)aTextField{   
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    59
    self.textFieldBeingEdited = aTextField;
3332
3c90a923f156 simplify the general settings and review minor stuff
koda
parents: 3330
diff changeset
    60
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    61
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",@"from the hog name table")
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    62
                                                                     style:UIBarButtonItemStylePlain
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    63
                                                                    target:self
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    64
                                                                    action:@selector(cancel:)];
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    65
    self.navigationItem.leftBarButtonItem = cancelButton;
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    66
    [cancelButton release];
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    67
    
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    68
    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Save",@"from the hog name table")
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    69
                                                                     style:UIBarButtonItemStyleDone
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    70
                                                                    target:self
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    71
                                                                    action:@selector(save:)];
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    72
    self.navigationItem.rightBarButtonItem = saveButton;
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    73
    [saveButton release];
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    74
}
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    75
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    76
// we save every time a textfield is edited, so we don't risk to update only the hogs or only the temname 
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    77
-(BOOL) textFieldShouldEndEditing:(UITextField *)aTextField {
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    78
    return [self save:nil];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    79
}
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
    80
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    81
// the textfield has been modified, check for empty strings and restore original navigation bar
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    82
-(void) textFieldDidEndEditing:(UITextField *)aTextField{
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    83
    if ([textFieldBeingEdited.text length] == 0) 
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    84
        textFieldBeingEdited.text = [NSString stringWithFormat:@"hedgehog %d",textFieldBeingEdited.tag];
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    85
3332
3c90a923f156 simplify the general settings and review minor stuff
koda
parents: 3330
diff changeset
    86
    self.textFieldBeingEdited = nil;
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    87
    self.navigationItem.rightBarButtonItem = self.navigationItem.backBarButtonItem;
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    88
    self.navigationItem.leftBarButtonItem = nil;
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    89
}
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    90
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    91
// limit the size of the field to 64 characters like in original frontend
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    92
-(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    93
    int limit = 64;
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    94
    return !([textField.text length] > limit && [string length] > range.length);
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    95
}
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    96
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
    97
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    98
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    99
#pragma mark View lifecycle
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   100
- (void)viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   101
    [super viewDidLoad];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   102
   
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   103
    // labels for the entries
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   104
    NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   105
                             NSLocalizedString(@"Grave",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   106
                             NSLocalizedString(@"Voice",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   107
                             NSLocalizedString(@"Fort",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   108
                             NSLocalizedString(@"Flag",@""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   109
                             NSLocalizedString(@"Level",@""),nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   110
    self.secondaryItems = array;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   111
    [array release];
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   112
    
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   113
    // insert controllers here
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   114
    NSMutableArray *controllersArray = [[NSMutableArray alloc] initWithCapacity:[secondaryItems count]];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   115
    
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   116
    FlagsViewController *flagsViewController = [[FlagsViewController alloc] initWithStyle:UITableViewStyleGrouped];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   117
    [controllersArray addObject:flagsViewController];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   118
    [flagsViewController release];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   119
    
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   120
    FortsViewController *fortsViewController = [[FortsViewController alloc] initWithStyle:UITableViewStyleGrouped];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   121
    [controllersArray addObject:fortsViewController];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   122
    [fortsViewController release];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   123
    
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   124
    self.secondaryControllers = controllersArray;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   125
    [controllersArray release];
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   126
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   127
    // 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
   128
    [[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
   129
    isWriteNeeded = NO;
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   130
}
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   131
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   132
- (void)viewWillAppear:(BOOL)animated {
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   133
    [super viewWillAppear:animated];
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3316
diff changeset
   134
    
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   135
    // load data about the team and write if there has been a change
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   136
    if (isWriteNeeded) 
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   137
        [self writeFile];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   138
    
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   139
    NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),self.title];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   140
	NSMutableDictionary *teamDict = [[NSMutableDictionary alloc] initWithContentsOfFile:teamFile];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   141
    self.teamDictionary = teamDict;
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   142
    [teamDict release];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   143
	[teamFile release];
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   144
    
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   145
    self.teamName = self.title;
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   146
    
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   147
    // load the images of the hat for aach hog
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   148
    NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   149
    UIImage *normalHogImage = [[UIImage alloc] initWithContentsOfFile:normalHogFile];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   150
    [normalHogFile release];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   151
    CGRect hogSpriteArea = CGRectMake(96, 0, 32, 32);
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   152
    CGImageRef cgImg = CGImageCreateWithImageInRect([normalHogImage CGImage], hogSpriteArea);
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   153
    [normalHogImage release];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   154
    UIImage *normalHogSprite = [[UIImage alloc] initWithCGImage:cgImg];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   155
    CGImageRelease(cgImg);
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   156
    
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   157
    NSArray *hogArray = [self.teamDictionary objectForKey:@"hedgehogs"];
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   158
    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[hogArray count]];
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   159
    for (NSDictionary *hog in hogArray) {
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   160
        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
   161
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   162
        UIImage *image = [[UIImage alloc] initWithContentsOfFile: hatFile];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3315
diff changeset
   163
        [hatFile release];
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   164
        CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32);
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   165
        CGImageRef cgImgage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea);
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   166
        [image release];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   167
        
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   168
        UIImage *hatSprite = [[UIImage alloc] initWithCGImage:cgImgage];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   169
        CGImageRelease(cgImgage);
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   170
        
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   171
        [array addObject:mergeTwoImages(normalHogSprite, hatSprite)];
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   172
        [hatSprite release];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   173
    }
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   174
    [normalHogSprite release];
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   175
    self.hatArray = array;
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   176
    [array release];
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   177
    
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   178
    [self.tableView reloadData];
3305
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
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   181
// write on file if there has been a change
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   182
-(void) viewWillDisappear:(BOOL)animated {
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   183
	[super viewWillDisappear:animated];
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   184
    if (isWriteNeeded) 
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   185
        [self writeFile];        
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   186
}
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   187
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   188
// 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
   189
-(void) setWriteNeeded {
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   190
    isWriteNeeded = YES;
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   191
}
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   192
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   193
-(void) writeFile {
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   194
    NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),self.title];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   195
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   196
    NSString *newTeamName = [self.teamDictionary objectForKey:@"teamname"];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   197
    if (![newTeamName isEqualToString:self.teamName]) {
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   198
        //delete old
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   199
        [[NSFileManager defaultManager] removeItemAtPath:teamFile error:NULL];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   200
        [teamFile release];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   201
        self.title = newTeamName;
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   202
        self.teamName = newTeamName;
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   203
        teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),newTeamName];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   204
    }
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   205
    
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   206
    [self.teamDictionary writeToFile:teamFile atomically:YES];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   207
    NSLog(@"writing: %@",teamDictionary);
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   208
    isWriteNeeded = NO;
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   209
	[teamFile release];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   210
}
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   211
3305
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 data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   214
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   215
    return 3;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   216
}
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
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   219
    NSInteger rows = 0;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   220
    switch (section) {
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   221
        case 0: // team name
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   222
            rows = 1;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   223
            break;
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   224
        case 1: // team members
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   225
            rows = MAX_HOGS;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   226
            break;
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   227
        case 2: // team details
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   228
            rows = [self.secondaryItems count];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   229
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   230
        default:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   231
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   232
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   233
    return rows;
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
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   237
    static NSString *CellIdentifier = @"Cell";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   238
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   239
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   240
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   241
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   242
                                       reuseIdentifier:CellIdentifier] autorelease];
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   243
        if ([indexPath section] != 2) {
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   244
            // create a uitextfield for each row, expand it to take the maximum size
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   245
            UITextField *aTextField;
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   246
            if ([indexPath section] == 1) {
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   247
                aTextField = [[UITextField alloc] 
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   248
                              initWithFrame:CGRectMake(42, 12, (cell.frame.size.width + cell.frame.size.width/3) - 42, 25)];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   249
            } else {
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   250
                aTextField = [[UITextField alloc] 
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   251
                              initWithFrame:CGRectMake(5, 12, (cell.frame.size.width + cell.frame.size.width/3) - 42, 25)];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   252
            }
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   253
            
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   254
            aTextField.clearsOnBeginEditing = NO;
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   255
            aTextField.returnKeyType = UIReturnKeyDone;
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   256
            aTextField.adjustsFontSizeToFitWidth = YES;
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   257
            aTextField.delegate = self;
3332
3c90a923f156 simplify the general settings and review minor stuff
koda
parents: 3330
diff changeset
   258
            aTextField.tag = [indexPath row];
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   259
            aTextField.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 2];
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   260
            aTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   261
            [aTextField addTarget:self action:@selector(save:) forControlEvents:UIControlEventEditingDidEndOnExit];
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   262
            [cell.contentView addSubview:aTextField];
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   263
            [aTextField release];
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   264
        }
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   265
    }
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   266
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   267
    NSArray *hogArray;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   268
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   269
    switch ([indexPath section]) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   270
        case 0:
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   271
            cell.imageView.image = nil;
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   272
            cell.accessoryType = UITableViewCellAccessoryNone;
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   273
            for (UIView *oneView in cell.contentView.subviews) {
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   274
                if ([oneView isMemberOfClass:[UITextField class]]) {
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   275
                    // we find the uitextfied and we'll use its tag to understand which one is being edited
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   276
                    UITextField *textFieldFound = (UITextField *)oneView;
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   277
                    textFieldFound.text = [self.teamDictionary objectForKey:@"teamname"];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   278
                    textFieldFound.tag = TEAMNAME_TAG;
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   279
                }
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   280
            }            
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   281
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   282
        case 1:
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   283
            hogArray = [self.teamDictionary objectForKey:@"hedgehogs"];
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   284
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   285
            cell.imageView.image = [self.hatArray objectAtIndex:row];
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   286
            
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   287
            for (UIView *oneView in cell.contentView.subviews) {
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   288
                if ([oneView isMemberOfClass:[UITextField class]]) {
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   289
                    // we find the uitextfied and we'll use its tag to understand which one is being edited
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   290
                    UITextField *textFieldFound = (UITextField *)oneView;
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   291
                    textFieldFound.text = [[hogArray objectAtIndex:row] objectForKey:@"hogname"];
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   292
                }
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   293
            }
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   294
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   295
            cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   296
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   297
        case 2:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   298
            cell.textLabel.text = [self.secondaryItems objectAtIndex:row];
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   299
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   300
            switch (row) {
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   301
                case 3: // flags
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   302
                    cell.imageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png",
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   303
                                                                             FLAGS_DIRECTORY(),[teamDictionary objectForKey:@"flag"]]];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   304
                    break;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   305
                default:
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   306
                    cell.imageView.image = nil;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   307
                    break;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   308
            }
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   309
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   310
        default:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   311
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   312
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   313
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   314
    return cell;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   315
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   316
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   317
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   318
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   319
#pragma mark Table view delegate
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   320
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   321
    NSInteger row = [indexPath row];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   322
    UITableViewController *nextController;
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   323
    UITableViewCell *cell;
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   324
    switch ([indexPath section]) {
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   325
        case 2:
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   326
            //TODO: this part should be rewrittend with lazy loading instead of an array of controllers
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   327
            nextController = [secondaryControllers objectAtIndex:row%2 ];              //TODO: fix the objectAtIndex
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   328
            nextController.title = [secondaryItems objectAtIndex:row];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   329
            [nextController setTeamDictionary:teamDictionary];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   330
            [self.navigationController pushViewController:nextController animated:YES];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   331
            break;            
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   332
        default:
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   333
            cell = [aTableView cellForRowAtIndexPath:indexPath];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   334
            for (UIView *oneView in cell.contentView.subviews) {
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   335
                if ([oneView isMemberOfClass:[UITextField class]]) {
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   336
                    textFieldBeingEdited = (UITextField *)oneView;
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   337
                    [textFieldBeingEdited becomeFirstResponder];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   338
                }
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   339
            }
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   340
            [aTableView deselectRowAtIndexPath:indexPath animated:NO];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   341
            break;
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   342
    }
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   343
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   344
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   345
// action to perform when you want to change a hog hat
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   346
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   347
    if (nil == hogChildController) {
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   348
        hogChildController = [[HogHatViewController alloc] initWithStyle:UITableViewStyleGrouped];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   349
    }
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   350
    
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   351
    // cache the dictionary file of the team, so that other controllers can modify it
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   352
    hogChildController.teamDictionary = self.teamDictionary;
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   353
    hogChildController.selectedHog = [indexPath row];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   354
    
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   355
    [self.navigationController pushViewController:hogChildController animated:YES];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   356
}
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   357
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   358
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   359
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   360
#pragma mark Memory management
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   361
-(void) didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   362
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   363
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   364
    // Relinquish ownership any cached data, images, etc that aren't in use.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   365
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   366
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   367
-(void) viewDidUnload {
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   368
    self.teamDictionary = nil;
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   369
    self.textFieldBeingEdited = nil;
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   370
    self.teamName = nil;
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   371
    self.hatArray = nil;
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   372
    self.secondaryItems = nil;
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   373
    self.secondaryControllers = nil;
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   374
    hogChildController = nil;
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   375
    [super viewDidUnload];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   376
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   377
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   378
-(void) dealloc {
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   379
    [teamDictionary release];
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   380
    [textFieldBeingEdited release];
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3329
diff changeset
   381
    [teamName release];
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   382
    [hatArray release];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   383
    [secondaryItems release];
3329
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   384
    [secondaryControllers release];
d8e41ee0b3ae add support to editing hog names
koda
parents: 3328
diff changeset
   385
    [hogChildController release];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   386
    [super dealloc];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   387
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   388
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   389
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   390
@end
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   391