cocoaTouch/SingleTeamViewController.m
author koda
Fri, 09 Apr 2010 11:09:26 +0000
changeset 3328 fe87c2242984
parent 3325 652a8ebdf667
child 3329 d8e41ee0b3ae
permissions -rw-r--r--
fix the save of the team and rearrange hat/name modification
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
    [controllersArray addObject:flagsViewController];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    42
    [flagsViewController release];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    43
    
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    44
    FortsViewController *fortsViewController = [[FortsViewController alloc] initWithStyle:UITableViewStyleGrouped];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    45
    [controllersArray addObject:fortsViewController];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    46
    [fortsViewController release];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    47
    
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    48
    self.secondaryControllers = controllersArray;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
    49
    [controllersArray release];
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    50
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    51
    // 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
    52
    [[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
    53
    isWriteNeeded = NO;
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    54
}
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    55
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    56
- (void)viewWillAppear:(BOOL)animated {
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    57
    [super viewWillAppear:animated];
3323
091cf214bdd5 implement an add/remove team in the ifrontend
koda
parents: 3316
diff changeset
    58
    
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    59
    // load data about the team and extract info
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    60
    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
    61
    if (isWriteNeeded) {
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    62
        [self.teamDictionary writeToFile:teamFile atomically:YES];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    63
        NSLog(@"writing: %@",teamDictionary);
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    64
        isWriteNeeded = NO;
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    65
    }
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    66
    
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    67
	NSMutableDictionary *teamDict = [[NSMutableDictionary alloc] initWithContentsOfFile:teamFile];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    68
    self.teamDictionary = teamDict;
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    69
    [teamDict release];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    70
    
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    71
	[teamFile release];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    72
        
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    73
    // 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
    74
    NSArray *hogArray = [self.teamDictionary objectForKey:@"hedgehogs"];
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    75
    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[hogArray count]];
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    76
    for (NSDictionary *hog in hogArray) {
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    77
        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
    78
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    79
        UIImage *image = [[UIImage alloc] initWithContentsOfFile: hatFile];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3315
diff changeset
    80
        [hatFile release];
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    81
        CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32);
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    82
        CGImageRef cgImgage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea);
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    83
        [image release];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    84
        
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    85
        UIImage *hatSprite = [[UIImage alloc] initWithCGImage:cgImgage];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    86
        [array addObject:hatSprite];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    87
        CGImageRelease(cgImgage);
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    88
        [hatSprite release];
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    89
    }
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    90
    self.hatArray = array;
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
    91
    [array release];
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    92
    
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
    93
    [self.tableView reloadData];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    94
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    95
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    96
-(void) viewWillDisappear:(BOOL)animated {
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    97
	[super viewWillDisappear:animated];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    98
	
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
    99
	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
   100
    if (isWriteNeeded) {
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   101
        [self.teamDictionary writeToFile:teamFile atomically:YES];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   102
        NSLog(@"writing: %@",teamDictionary);
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   103
        isWriteNeeded = NO;
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   104
    }
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   105
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   106
	[teamFile release];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   107
}
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   108
// 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
   109
-(void) setWriteNeeded {
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   110
    isWriteNeeded = YES;
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   111
}
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   112
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   113
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   114
#pragma mark Table view data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   115
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
    return 3;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3308
diff changeset
   120
    NSInteger rows = 0;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   121
    switch (section) {
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   122
        case 0: // team name
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   123
            rows = 1;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   124
            break;
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   125
        case 1: // team members
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   126
            rows = MAX_HOGS;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   127
            break;
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   128
        case 2: // team details
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   129
            rows = [self.secondaryItems count];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   130
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   131
        default:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   132
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   133
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   134
    return rows;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   135
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   138
    static NSString *CellIdentifier = @"Cell";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   139
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   140
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   141
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   142
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   143
                                       reuseIdentifier:CellIdentifier] autorelease];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   144
    }
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   145
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   146
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   147
    NSArray *hogArray;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   148
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   149
    switch ([indexPath section]) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   150
        case 0:
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   151
            cell.textLabel.text = self.title;
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   152
            cell.imageView.image = nil;
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   153
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   154
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   155
        case 1:
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   156
            hogArray = [self.teamDictionary objectForKey:@"hedgehogs"];
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   157
            cell.textLabel.text = [[hogArray objectAtIndex:row] objectForKey:@"hogname"];
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   158
            cell.imageView.image = [self.hatArray objectAtIndex:row];
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   159
            cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   160
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   161
        case 2:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   162
            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
   163
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   164
            switch (row) {
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   165
                case 3: // flags
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   166
                    cell.imageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png",
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   167
                                                                             FLAGS_DIRECTORY(),[teamDictionary objectForKey:@"flag"]]];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   168
                    break;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   169
                default:
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   170
                    cell.imageView.image = nil;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   171
                    break;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   172
            }
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   173
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   174
        default:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   175
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   176
    }
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
    return cell;
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
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   183
// Override to support conditional editing of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   184
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   185
    // 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
   186
    return YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   187
}
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   190
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   191
// Override to support editing the table view.
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   192
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   193
 forRowAtIndexPath:(NSIndexPath *)indexPath {
3305
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
    if (editingStyle == UITableViewCellEditingStyleDelete) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   196
        // Delete the row from the data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   197
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
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
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   200
        // 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
   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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   205
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   206
// Override to support rearranging the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   207
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
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
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   213
// Override to support conditional rearranging of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   214
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   215
    // 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
   216
    return YES;
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
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   219
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   220
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   221
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   222
#pragma mark Table view delegate
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   223
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   224
    NSInteger row = [indexPath row];
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   225
    UITableViewController *nextController;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   226
    if (1 == [indexPath section]) {
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   227
        //TODO: hog name pref, causes segfault
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   228
    }
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   229
    if (2 == [indexPath section]) {
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   230
        //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
   231
        nextController = [secondaryControllers objectAtIndex:row%2 ];              //TODO: fix the objectAtIndex
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   232
        nextController.title = [secondaryItems objectAtIndex:row];
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   233
        [nextController setTeamDictionary:teamDictionary];
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   234
    }
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   235
    [self.navigationController pushViewController:nextController animated:YES];
3305
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
3328
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   238
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   239
    if (nil == hogChildController) {
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   240
        hogChildController = [[HogHatViewController alloc] initWithStyle:UITableViewStyleGrouped];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   241
    }
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   242
    
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   243
    // 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
   244
    hogChildController.teamDictionary = self.teamDictionary;
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   245
    hogChildController.selectedHog = [indexPath row];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   246
    
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   247
    [self.navigationController pushViewController:hogChildController animated:YES];
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   248
}
fe87c2242984 fix the save of the team and rearrange hat/name modification
koda
parents: 3325
diff changeset
   249
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   250
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   251
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   252
#pragma mark Memory management
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   253
-(void) didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   254
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   255
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   256
    // Relinquish ownership any cached data, images, etc that aren't in use.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   257
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   258
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   259
-(void) viewDidUnload {
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   260
    self.secondaryControllers = nil;
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   261
    self.secondaryItems = nil;
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   262
    self.hatArray = nil;
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   263
    self.teamDictionary = nil;
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   264
    [super viewDidUnload];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   265
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   266
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   267
-(void) dealloc {
3325
652a8ebdf667 moved around team creation
koda
parents: 3323
diff changeset
   268
    [secondaryControllers release];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   269
    [secondaryItems release];
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   270
    [hatArray release];
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3312
diff changeset
   271
    [teamDictionary release];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   272
    [super dealloc];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   273
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   274
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   275
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   276
@end
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   277