cocoaTouch/SingleTeamViewController.m
changeset 3305 91074496d5c9
child 3308 b6dcae4b6d2c
equal deleted inserted replaced
3304:8690a3aa93b5 3305:91074496d5c9
       
     1 //
       
     2 //  SingleTeamViewController.m
       
     3 //  HedgewarsMobile
       
     4 //
       
     5 //  Created by Vittorio on 02/04/10.
       
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
       
     7 //
       
     8 
       
     9 #import "SingleTeamViewController.h"
       
    10 #import "HogHatViewController.h"
       
    11 
       
    12 @implementation SingleTeamViewController
       
    13 @synthesize hogsList, secondaryItems, teamName;
       
    14 
       
    15 
       
    16 #pragma mark -
       
    17 #pragma mark View lifecycle
       
    18 - (void)viewDidLoad {
       
    19     [super viewDidLoad];
       
    20 
       
    21     // Uncomment the following line to preserve selection between presentations.
       
    22     //self.clearsSelectionOnViewWillAppear = NO;
       
    23  
       
    24     // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
       
    25     // self.navigationItem.rightBarButtonItem = self.editButtonItem;
       
    26    
       
    27     NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:
       
    28                              NSLocalizedString(@"Color",@""),
       
    29                              NSLocalizedString(@"Grave",@""),
       
    30                              NSLocalizedString(@"Voice",@""),
       
    31                              NSLocalizedString(@"Fort",@""),
       
    32                              NSLocalizedString(@"Flag",@""),
       
    33                              NSLocalizedString(@"Level",@""),nil];
       
    34     self.secondaryItems = array;
       
    35     [array release];
       
    36 }
       
    37 
       
    38 
       
    39 - (void)viewWillAppear:(BOOL)animated {
       
    40     [super viewWillAppear:animated];
       
    41     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
       
    42     NSString *teamFile = [[NSString alloc] initWithFormat:@"%@Teams/%@.plist",[paths objectAtIndex:0],self.teamName];
       
    43     NSDictionary *teamDict = [[NSDictionary alloc] initWithContentsOfFile:teamFile];
       
    44     [teamFile release];
       
    45     
       
    46     self.hogsList = [teamDict objectForKey:@"hedgehogs"];
       
    47     self.teamName = [teamDict objectForKey:@"teamname"];
       
    48     [teamDict release];
       
    49     self.title = teamName;
       
    50 }
       
    51 
       
    52 /*
       
    53 - (void)viewDidAppear:(BOOL)animated {
       
    54     [super viewDidAppear:animated];
       
    55 }
       
    56 */
       
    57 /*
       
    58 - (void)viewWillDisappear:(BOOL)animated {
       
    59     [super viewWillDisappear:animated];
       
    60 }
       
    61 */
       
    62 /*
       
    63 - (void)viewDidDisappear:(BOOL)animated {
       
    64     [super viewDidDisappear:animated];
       
    65 }
       
    66 */
       
    67 
       
    68 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
       
    69     return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
       
    70 }
       
    71 
       
    72 
       
    73 #pragma mark -
       
    74 #pragma mark Table view data source
       
    75 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
       
    76     return 3;
       
    77 }
       
    78 
       
    79 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
       
    80     NSInteger rows;
       
    81     switch (section) {
       
    82         case 0:
       
    83             rows = 1;
       
    84             break;
       
    85         case 1:
       
    86             rows = 8;
       
    87             break;
       
    88         case 2:
       
    89             rows = 6;
       
    90             break;
       
    91         default:
       
    92             break;
       
    93     }
       
    94     return rows;
       
    95 }
       
    96 
       
    97 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
       
    98     static NSString *CellIdentifier = @"Cell";
       
    99     
       
   100     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
       
   101     if (cell == nil) {
       
   102         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
       
   103                                        reuseIdentifier:CellIdentifier] autorelease];
       
   104     }
       
   105     
       
   106     NSInteger row = [indexPath row];
       
   107     switch ([indexPath section]) {
       
   108         case 0:
       
   109             cell.textLabel.text = teamName;
       
   110             break;
       
   111         case 1:
       
   112             cell.textLabel.text = [[self.hogsList objectAtIndex:row] objectForKey:@"hogname"];
       
   113             cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
       
   114             break;
       
   115         case 2:
       
   116             cell.textLabel.text = [self.secondaryItems objectAtIndex:row];
       
   117             break;
       
   118         default:
       
   119             break;
       
   120     }
       
   121     
       
   122     return cell;
       
   123 }
       
   124 
       
   125 
       
   126 /*
       
   127 // Override to support conditional editing of the table view.
       
   128 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
       
   129     // Return NO if you do not want the specified item to be editable.
       
   130     return YES;
       
   131 }
       
   132 */
       
   133 
       
   134 
       
   135 /*
       
   136 // Override to support editing the table view.
       
   137 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
       
   138     
       
   139     if (editingStyle == UITableViewCellEditingStyleDelete) {
       
   140         // Delete the row from the data source
       
   141         [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
       
   142     }   
       
   143     else if (editingStyle == UITableViewCellEditingStyleInsert) {
       
   144         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
       
   145     }   
       
   146 }
       
   147 */
       
   148 
       
   149 
       
   150 /*
       
   151 // Override to support rearranging the table view.
       
   152 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
       
   153 }
       
   154 */
       
   155 
       
   156 
       
   157 /*
       
   158 // Override to support conditional rearranging of the table view.
       
   159 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
       
   160     // Return NO if you do not want the item to be re-orderable.
       
   161     return YES;
       
   162 }
       
   163 */
       
   164 
       
   165 
       
   166 #pragma mark -
       
   167 #pragma mark Table view delegate
       
   168 
       
   169 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
       
   170     if (1 == [indexPath section]) {
       
   171         if (nil == hogChildController) {
       
   172             hogChildController = [[HogHatViewController alloc] initWithStyle:UITableViewStyleGrouped];
       
   173         }
       
   174     
       
   175         hogChildController.hog = [hogsList objectAtIndex:[indexPath row]];
       
   176         //NSLog(@"%@",hogChildController.hog);
       
   177         [self.navigationController pushViewController:hogChildController animated:YES];
       
   178     }
       
   179 }
       
   180 
       
   181 
       
   182 #pragma mark -
       
   183 #pragma mark Memory management
       
   184 
       
   185 -(void) didReceiveMemoryWarning {
       
   186     // Releases the view if it doesn't have a superview.
       
   187     [super didReceiveMemoryWarning];
       
   188     // Relinquish ownership any cached data, images, etc that aren't in use.
       
   189 }
       
   190 
       
   191 -(void) viewDidUnload {
       
   192     self.hogsList = nil;
       
   193     self.secondaryItems = nil;
       
   194     self.teamName = nil;
       
   195 }
       
   196 
       
   197 
       
   198 -(void) dealloc {
       
   199     [secondaryItems release];
       
   200     [hogsList release];
       
   201     [teamName release];
       
   202     [super dealloc];
       
   203 }
       
   204 
       
   205 
       
   206 @end
       
   207