cocoaTouch/SingleTeamViewController.m
changeset 3312 6d8f1c76756d
parent 3308 b6dcae4b6d2c
child 3315 4e2813713358
equal deleted inserted replaced
3311:18436bb84bfe 3312:6d8f1c76756d
     8 
     8 
     9 #import "SingleTeamViewController.h"
     9 #import "SingleTeamViewController.h"
    10 #import "HogHatViewController.h"
    10 #import "HogHatViewController.h"
    11 
    11 
    12 @implementation SingleTeamViewController
    12 @implementation SingleTeamViewController
    13 @synthesize hogsList, secondaryItems, teamName;
    13 @synthesize hogsList, hatList, secondaryItems, teamName;
    14 
    14 
    15 
    15 
    16 #pragma mark -
    16 #pragma mark -
    17 #pragma mark View lifecycle
    17 #pragma mark View lifecycle
    18 - (void)viewDidLoad {
    18 - (void)viewDidLoad {
    36 }
    36 }
    37 
    37 
    38 
    38 
    39 - (void)viewWillAppear:(BOOL)animated {
    39 - (void)viewWillAppear:(BOOL)animated {
    40     [super viewWillAppear:animated];
    40     [super viewWillAppear:animated];
       
    41     
       
    42     // load data about the team and extract info
    41     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    43     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    42     NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/Teams/%@.plist",[paths objectAtIndex:0],self.teamName];
    44     NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/Teams/%@.plist",[paths objectAtIndex:0],self.teamName];
    43     NSDictionary *teamDict = [[NSDictionary alloc] initWithContentsOfFile:teamFile];
    45     NSDictionary *teamDict = [[NSDictionary alloc] initWithContentsOfFile:teamFile];
    44     [teamFile release];
    46     [teamFile release];
    45     
    47     
       
    48     // grab the hog list
    46     self.hogsList = [teamDict objectForKey:@"hedgehogs"];
    49     self.hogsList = [teamDict objectForKey:@"hedgehogs"];
       
    50     // grab the name of the team
    47     self.teamName = [teamDict objectForKey:@"teamname"];
    51     self.teamName = [teamDict objectForKey:@"teamname"];
       
    52     self.title = self.teamName;
    48     [teamDict release];
    53     [teamDict release];
    49     self.title = teamName;
    54     
       
    55     // load the images of the hat for aach hog
       
    56     NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[self.hogsList count]];
       
    57     for (NSDictionary *hog in self.hogsList) {
       
    58         NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/Data/Graphics/Hats/%@.png",[[NSBundle mainBundle] resourcePath],[hog objectForKey:@"hat"]];
       
    59 
       
    60         UIImage *image = [[UIImage alloc] initWithContentsOfFile: hatFile];
       
    61         CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32);
       
    62         CGImageRef cgImgage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea);
       
    63         [image release];
       
    64         
       
    65         UIImage *hatSprite = [[UIImage alloc] initWithCGImage:cgImgage];
       
    66         [array addObject:hatSprite];
       
    67         CGImageRelease(cgImgage);
       
    68         [hatSprite release];
       
    69     }
       
    70     self.hatList = array;
       
    71     [array release];
    50 }
    72 }
    51 
    73 
    52 /*
    74 /*
    53 - (void)viewDidAppear:(BOOL)animated {
    75 - (void)viewDidAppear:(BOOL)animated {
    54     [super viewDidAppear:animated];
    76     [super viewDidAppear:animated];
    75 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    97 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    76     return 3;
    98     return 3;
    77 }
    99 }
    78 
   100 
    79 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   101 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    80     NSInteger rows;
   102     NSInteger rows = 0;
    81     switch (section) {
   103     switch (section) {
    82         case 0:
   104         case 0:
    83             rows = 1;
   105             rows = 1;
    84             break;
   106             break;
    85         case 1:
   107         case 1:
   109             cell.textLabel.text = teamName;
   131             cell.textLabel.text = teamName;
   110             break;
   132             break;
   111         case 1:
   133         case 1:
   112             cell.textLabel.text = [[self.hogsList objectAtIndex:row] objectForKey:@"hogname"];
   134             cell.textLabel.text = [[self.hogsList objectAtIndex:row] objectForKey:@"hogname"];
   113             cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
   135             cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
       
   136             cell.imageView.image = [self.hatList objectAtIndex:row];
   114             break;
   137             break;
   115         case 2:
   138         case 2:
   116             cell.textLabel.text = [self.secondaryItems objectAtIndex:row];
   139             cell.textLabel.text = [self.secondaryItems objectAtIndex:row];
   117             break;
   140             break;
   118         default:
   141         default: