cocoaTouch/TeamSettingsViewController.m
author koda
Tue, 06 Apr 2010 02:39:06 +0000
changeset 3308 b6dcae4b6d2c
parent 3305 91074496d5c9
child 3315 4e2813713358
permissions -rw-r--r--
make the tables work also on iphone make the popover menu work also on iphone
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;
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    26
    NSLog(@"%@\n%@", teamsDirectory, contents);
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
    // Override to allow orientations other than the default portrait orientation.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    36
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    40
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    41
#pragma mark Table view data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    42
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    43
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    44
    // Return the number of sections.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    45
    return 1;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    49
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    50
    // Return the number of rows in the section.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    51
    return [list count];
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    55
// Customize the appearance of table view cells.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    56
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    57
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
    static NSString *CellIdentifier = @"Cell";
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
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    61
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    62
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
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
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    65
    NSUInteger row = [indexPath row]; 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    66
    NSString *rowString = [[list objectAtIndex:row] stringByDeletingPathExtension]; 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    67
    cell.textLabel.text = rowString; 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    68
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    69
    //cell.imageView.image = [UIImage imageNamed:@"Default.png"];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    70
    //[rowString release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    71
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    72
    return cell;
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
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    77
// Override to support conditional editing of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    78
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    79
    // 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
    80
    return YES;
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
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    86
// Override to support editing the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    87
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    88
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    89
    if (editingStyle == UITableViewCellEditingStyleDelete) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    90
        // Delete the row from the data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    91
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
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
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    94
        // 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
    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
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   101
// Override to support rearranging the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   102
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
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
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   108
// Override to support conditional rearranging of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   109
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   110
    // 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
   111
    return YES;
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   117
#pragma mark Table view delegate
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   118
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
    if (childController == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   120
        childController = [[SingleTeamViewController alloc] initWithStyle:UITableViewStyleGrouped];
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
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   123
    NSInteger row = [indexPath row];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   124
    NSString *selectedTeam = [[list objectAtIndex:row] stringByDeletingPathExtension];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   125
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   126
    childController.teamName = selectedTeam;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   127
    [self.navigationController pushViewController:childController animated:YES];
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
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   131
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   132
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Hey, do you see the disclosure button?" 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   133
                                                    message:@"If you're trying to drill down, touch that instead" 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   134
                                                   delegate:nil
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   135
                                          cancelButtonTitle:@"Won't happen again"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
                                          otherButtonTitles:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
    [alert show];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   138
    [alert release];
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   142
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   143
#pragma mark Memory management
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
- (void)didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   146
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   147
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   148
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   149
    // Relinquish ownership any cached data, images, etc that aren't in use.
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
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   153
- (void)viewDidUnload {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   154
    // 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
   155
    // For example: self.myOutlet = nil;
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
- (void)dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   160
    [list release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   161
    if (nil != childController)
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   162
        [childController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   163
    [super dealloc];
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
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   167
@end
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   168