cocoaTouch/TeamSettingsViewController.m
author nemo
Mon, 05 Apr 2010 17:22:54 +0000
changeset 3307 275af46392bd
parent 3305 91074496d5c9
child 3308 b6dcae4b6d2c
permissions -rw-r--r--
These don't belong here.
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];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    19
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    20
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    21
    NSString *teamsDirectory = [[paths objectAtIndex:0] stringByAppendingString:@"Teams/"];
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;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    26
   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    27
    // Uncomment the following line to preserve selection between presentations.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    28
    // self.clearsSelectionOnViewWillAppear = NO;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    29
    // 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
    30
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    31
}
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
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    34
    // Override to allow orientations other than the default portrait orientation.
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    42
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    43
    // Return the number of sections.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    44
    return 1;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    47
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    48
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    49
    // Return the number of rows in the section.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    50
    return [list count];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    51
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    52
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
// Customize the appearance of table view cells.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    55
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    56
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    57
    static NSString *CellIdentifier = @"Cell";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    60
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    61
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    62
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    63
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
    NSUInteger row = [indexPath row]; 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    65
    NSString *rowString = [[list objectAtIndex:row] stringByDeletingPathExtension]; 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    66
    cell.textLabel.text = rowString; 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    67
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    68
    //cell.imageView.image = [UIImage imageNamed:@"Default.png"];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    69
    //[rowString release];
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
    return cell;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    72
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    73
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    74
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
// Override to support conditional editing of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    77
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    78
    // 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
    79
    return YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    80
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    81
*/
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    84
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    85
// Override to support editing the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    86
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    87
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    88
    if (editingStyle == UITableViewCellEditingStyleDelete) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    89
        // Delete the row from the data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    90
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
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
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    93
        // 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
    94
    }   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    95
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    96
*/
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
// Override to support rearranging the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   101
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   102
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   103
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   104
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   105
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
// Override to support conditional rearranging of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   108
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   109
    // 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
   110
    return YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   111
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   112
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   113
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   114
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   115
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
#pragma mark Table view delegate
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   117
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   118
    if (childController == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
        childController = [[SingleTeamViewController alloc] initWithStyle:UITableViewStyleGrouped];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   120
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   121
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   122
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   123
    NSString *selectedTeam = [[list objectAtIndex:row] stringByDeletingPathExtension];
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
    childController.teamName = selectedTeam;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   126
    [self.navigationController pushViewController:childController animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   127
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   128
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   129
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   130
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   131
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Hey, do you see the disclosure button?" 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   132
                                                    message:@"If you're trying to drill down, touch that instead" 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   133
                                                   delegate:nil
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   134
                                          cancelButtonTitle:@"Won't happen again"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   135
                                          otherButtonTitles:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
    [alert show];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
    [alert release];
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
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   140
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   141
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   142
#pragma mark Memory management
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   143
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   144
- (void)didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   145
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   146
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   147
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   148
    // Relinquish ownership any cached data, images, etc that aren't in use.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   149
}
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
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   152
- (void)viewDidUnload {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   153
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   154
    // For example: self.myOutlet = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   155
}
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
- (void)dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   159
    [list release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   160
    if (nil != childController)
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   161
        [childController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   162
    [super dealloc];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   163
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   164
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   165
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   166
@end
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   167