cocoaTouch/iPad/HogHatViewController.m
author koda
Fri, 02 Apr 2010 22:44:14 +0000
changeset 3270 9bd8fb1707b9
child 3276 039145459ac8
permissions -rw-r--r--
initial support for hat selection on the ifrontend
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3270
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
     1
//
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
     2
//  HogHatViewController.m
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
     3
//  HedgewarsMobile
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
     4
//
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
     5
//  Created by Vittorio on 02/04/10.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
     7
//
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
     8
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
     9
#import "HogHatViewController.h"
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    10
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    11
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    12
@implementation HogHatViewController
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    13
@synthesize hatList, hog;
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    14
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    15
#pragma mark -
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    16
#pragma mark View lifecycle
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    17
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    18
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    19
- (void)viewDidLoad {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    20
    [super viewDidLoad];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    21
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    22
    //NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    23
    NSString *hatPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Hats/"];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    24
    NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:hatPath
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    25
                                                                         error:NULL];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    26
    self.hatList = array;
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    27
    //NSLog(@"%@", hatList);
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    28
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    29
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    30
- (void)viewWillAppear:(BOOL)animated {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    31
    [super viewWillAppear:animated];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    32
    self.title = [hog objectForKey:@"hogname"];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    33
    [self.tableView reloadData];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    34
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    35
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    36
/*
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    37
- (void)viewDidAppear:(BOOL)animated {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    38
    [super viewDidAppear:animated];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    39
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    40
*/
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    41
/*
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    42
- (void)viewWillDisappear:(BOOL)animated {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    43
    [super viewWillDisappear:animated];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    44
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    45
*/
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    46
/*
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    47
- (void)viewDidDisappear:(BOOL)animated {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    48
    [super viewDidDisappear:animated];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    49
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    50
*/
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    51
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    52
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    53
    // Override to allow orientations other than the default portrait orientation.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    54
    return YES;
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    55
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    56
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    57
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    58
#pragma mark -
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    59
#pragma mark Table view data source
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    60
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    61
    return 2;
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    62
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    63
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    64
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    65
    NSInteger rows;
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    66
    if (0 == section) 
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    67
        rows = 1;
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    68
    else
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    69
        rows = [self.hatList count];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    70
    return rows;
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    71
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    72
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    73
// Customize the appearance of table view cells.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    74
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    75
    
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    76
    static NSString *CellIdentifier = @"Cell";
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    77
    
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    78
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    79
    if (cell == nil) {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    80
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    81
    }
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    82
    
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    83
    if (0 == [indexPath section]) 
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    84
        cell.textLabel.text = [hog objectForKey:@"hogname"];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    85
    else
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    86
        cell.textLabel.text = [[hatList objectAtIndex:[indexPath row]] stringByDeletingPathExtension];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    87
    
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    88
    return cell;
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    89
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    90
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    91
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    92
/*
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    93
// Override to support conditional editing of the table view.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    94
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    95
    // Return NO if you do not want the specified item to be editable.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    96
    return YES;
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    97
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    98
*/
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
    99
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   100
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   101
/*
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   102
// Override to support editing the table view.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   103
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   104
    
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   105
    if (editingStyle == UITableViewCellEditingStyleDelete) {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   106
        // Delete the row from the data source
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   107
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   108
    }   
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   109
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   110
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   111
    }   
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   112
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   113
*/
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   114
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   115
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   116
/*
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   117
// Override to support rearranging the table view.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   118
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   119
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   120
*/
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   121
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   122
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   123
/*
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   124
// Override to support conditional rearranging of the table view.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   125
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   126
    // Return NO if you do not want the item to be re-orderable.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   127
    return YES;
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   128
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   129
*/
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   130
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   131
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   132
#pragma mark -
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   133
#pragma mark Table view delegate
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   134
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   135
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   136
    // Navigation logic may go here. Create and push another view controller.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   137
	/*
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   138
	 <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   139
     // ...
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   140
     // Pass the selected object to the new view controller.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   141
	 [self.navigationController pushViewController:detailViewController animated:YES];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   142
	 [detailViewController release];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   143
	 */
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   144
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   145
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   146
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   147
#pragma mark -
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   148
#pragma mark Memory management
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   149
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   150
- (void)didReceiveMemoryWarning {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   151
    // Releases the view if it doesn't have a superview.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   152
    [super didReceiveMemoryWarning];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   153
    
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   154
    // Relinquish ownership any cached data, images, etc that aren't in use.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   155
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   156
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   157
- (void)viewDidUnload {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   158
    [super viewDidUnload];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   159
    self.hatList = nil;
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   160
    self.hog = nil;
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   161
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   162
    // For example: self.myOutlet = nil;
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   163
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   164
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   165
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   166
- (void)dealloc {
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   167
    [hog release];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   168
    [hatList release];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   169
    [super dealloc];
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   170
}
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   171
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   172
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   173
@end
9bd8fb1707b9 initial support for hat selection on the ifrontend
koda
parents:
diff changeset
   174