cocoaTouch/TeamSettingsViewController.m
author koda
Wed, 07 Apr 2010 03:02:19 +0000
changeset 3318 591c42242106
parent 3315 4e2813713358
child 3323 091cf214bdd5
permissions -rw-r--r--
much better
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
//  TeamSettingsViewController.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 "TeamSettingsViewController.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    10
#import "SingleTeamViewController.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    11
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    12
@implementation TeamSettingsViewController
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    13
@synthesize list;
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    16
#pragma mark View lifecycle
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    17
- (void)viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    18
    [super viewDidLoad];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    19
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    20
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    21
    NSString *teamsDirectory = [[paths objectAtIndex:0] stringByAppendingString:@"/Teams/"];
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
    NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:teamsDirectory
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    24
                                                                            error:NULL];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    25
    self.list = contents;
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3308
diff changeset
    26
    //NSLog(@"%@\n%@", teamsDirectory, contents);
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    27
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    28
    // Uncomment the following line to preserve selection between presentations.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    29
    // self.clearsSelectionOnViewWillAppear = NO;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    30
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    31
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    32
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    33
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    34
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    35
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    36
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    37
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    38
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    39
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    40
#pragma mark Table view data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    41
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    42
    // Return the number of sections.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    43
    return 1;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    44
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    45
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    46
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    47
    // Return the number of rows in the section.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    48
    return [list count];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    49
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    50
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    51
// Customize the appearance of table view cells.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    52
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    53
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    54
    static NSString *CellIdentifier = @"Cell";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    55
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    56
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    57
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    60
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    61
    NSUInteger row = [indexPath row]; 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    62
    NSString *rowString = [[list objectAtIndex:row] stringByDeletingPathExtension]; 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    63
    cell.textLabel.text = rowString; 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    65
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    66
    return cell;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    67
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    68
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    69
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    70
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    71
// Override to support conditional editing of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    72
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    73
    // 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
    74
    return YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    75
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    76
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    77
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    78
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    79
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    80
// Override to support editing the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    81
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    82
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    83
    if (editingStyle == UITableViewCellEditingStyleDelete) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    84
        // Delete the row from the data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    85
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    86
    }   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    87
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    88
        // 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
    89
    }   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    90
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    91
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    92
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    93
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
// Override to support rearranging the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    96
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    97
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    98
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    99
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   100
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   101
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   102
// Override to support conditional rearranging of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   103
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   104
    // 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
   105
    return YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   106
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   107
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   108
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   109
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   110
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   111
#pragma mark Table view delegate
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   112
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   113
    if (childController == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   114
        childController = [[SingleTeamViewController alloc] initWithStyle:UITableViewStyleGrouped];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   115
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   117
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   118
    NSString *selectedTeam = [[list objectAtIndex:row] stringByDeletingPathExtension];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
    
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3308
diff changeset
   120
    childController.title = selectedTeam;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   121
    [self.navigationController pushViewController:childController animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   122
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   123
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   124
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   125
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   126
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Hey, do you see the disclosure button?" 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   127
                                                    message:@"If you're trying to drill down, touch that instead" 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   128
                                                   delegate:nil
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   129
                                          cancelButtonTitle:@"Won't happen again"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   130
                                          otherButtonTitles:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   131
    [alert show];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   132
    [alert release];
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
*/
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
#pragma mark Memory management
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   138
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   139
- (void)didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   140
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   141
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   142
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   143
    // Relinquish ownership any cached data, images, etc that aren't in use.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   144
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   145
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   146
- (void)viewDidUnload {
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3308
diff changeset
   147
    self.list = nil;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   148
}
3315
4e2813713358 usa a cached dictionary and write only when needed
koda
parents: 3308
diff changeset
   149
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   150
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   151
- (void)dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   152
    [list release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   153
    if (nil != childController)
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   154
        [childController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   155
    [super dealloc];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   156
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   157
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   158
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   159
@end
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   160