cocoaTouch/TeamSettingsViewController.m
changeset 3330 987ec27b6042
parent 3328 fe87c2242984
child 3335 2520ee7a5484
equal deleted inserted replaced
3329:d8e41ee0b3ae 3330:987ec27b6042
    18     return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    18     return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    19 }
    19 }
    20 
    20 
    21 #pragma mark -
    21 #pragma mark -
    22 #pragma mark View lifecycle
    22 #pragma mark View lifecycle
    23 - (void)viewDidLoad {
    23 // add an edit button
       
    24 -(void) viewDidLoad {
    24     [super viewDidLoad];
    25     [super viewDidLoad];
    25 
    26 
    26     UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Edit",@"from the team navigation")
    27     UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Edit",@"from the team navigation")
    27                                                                    style:UIBarButtonItemStyleBordered
    28                                                                    style:UIBarButtonItemStyleBordered
    28                                                                   target:self
    29                                                                   target:self
    29                                                                   action:@selector(toggleEdit:)];
    30                                                                   action:@selector(toggleEdit:)];
    30     self.navigationItem.rightBarButtonItem = editButton;
    31     self.navigationItem.rightBarButtonItem = editButton;
    31     [editButton release];
    32     [editButton release];
       
    33 }
       
    34 
       
    35 // load the list of teams in the teams directory
       
    36 -(void) viewWillAppear:(BOOL)animated {
       
    37     [super viewWillAppear:animated];
    32     
    38     
    33     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    39     NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL];
    34     NSString *teamsDirectory = [[paths objectAtIndex:0] stringByAppendingString:@"/Teams/"];
       
    35     
       
    36     NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:teamsDirectory error:NULL];
       
    37     NSMutableArray *array = [[NSMutableArray alloc] initWithArray: contentsOfDir copyItems:YES];
    40     NSMutableArray *array = [[NSMutableArray alloc] initWithArray: contentsOfDir copyItems:YES];
    38     self.listOfTeams = array;
    41     self.listOfTeams = array;
    39     [array release];
    42     [array release];
       
    43     
       
    44     [self.tableView reloadData];
    40     NSLog(@"files: %@", self.listOfTeams);
    45     NSLog(@"files: %@", self.listOfTeams);
    41 }
    46 }
    42 
    47 
    43 // modifies the navigation bar to add the "Add" and "Done" buttons
    48 // modifies the navigation bar to add the "Add" and "Done" buttons
    44 -(void) toggleEdit:(id) sender {
    49 -(void) toggleEdit:(id) sender {
   102 
   107 
   103 // delete the row and the file
   108 // delete the row and the file
   104 -(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
   109 -(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
   105     NSUInteger row = [indexPath row];
   110     NSUInteger row = [indexPath row];
   106     
   111     
   107     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   112     NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@",TEAMS_DIRECTORY(),[self.listOfTeams objectAtIndex:row]];
   108     NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/Teams/%@",[paths objectAtIndex:0],[self.listOfTeams objectAtIndex:row]];
       
   109 
       
   110     [[NSFileManager defaultManager] removeItemAtPath:teamFile error:NULL];
   113     [[NSFileManager defaultManager] removeItemAtPath:teamFile error:NULL];
   111     [teamFile release];
   114     [teamFile release];
   112     
   115     
   113     [self.listOfTeams removeObjectAtIndex:row];
   116     [self.listOfTeams removeObjectAtIndex:row];
   114     [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
   117     [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
   126         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
   129         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
   127     }   
   130     }   
   128 }
   131 }
   129 */
   132 */
   130 
   133 
   131 /*
       
   132 // Override to support rearranging the table view.
       
   133 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
       
   134 }
       
   135 */
       
   136 
       
   137 /*
       
   138 // Override to support conditional rearranging of the table view.
       
   139 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
       
   140     // Return NO if you do not want the item to be re-orderable.
       
   141     return YES;
       
   142 }
       
   143 */
       
   144 
       
   145 
   134 
   146 #pragma mark -
   135 #pragma mark -
   147 #pragma mark Table view delegate
   136 #pragma mark Table view delegate
   148 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   137 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   149     if (childController == nil) {
   138     if (childController == nil) {
   150         childController = [[SingleTeamViewController alloc] initWithStyle:UITableViewStyleGrouped];
   139         childController = [[SingleTeamViewController alloc] initWithStyle:UITableViewStyleGrouped];
   151     }
   140     }
   152     
   141     
   153     NSInteger row = [indexPath row];
   142     NSInteger row = [indexPath row];
   154     NSString *selectedTeamFile = [listOfTeams objectAtIndex:row];
   143     NSString *selectedTeamFile = [listOfTeams objectAtIndex:row];
   155     NSLog(@"%@",selectedTeamFile);
   144     NSLog(@"%@",selectedTeamFile);
   156     
   145     
       
   146     // this must be set so childController can load the correct plist
   157     childController.title = [selectedTeamFile stringByDeletingPathExtension];
   147     childController.title = [selectedTeamFile stringByDeletingPathExtension];
   158     [childController.tableView setContentOffset:CGPointMake(0,0) animated:NO];
   148     [childController.tableView setContentOffset:CGPointMake(0,0) animated:NO];
   159 
   149 
   160     // this must be set so childController can load the correct plist
       
   161     //childController.title = [[listOfTeams objectAtIndex:row] stringByDeletingPathExtension];
       
   162     [self.navigationController pushViewController:childController animated:YES];
   150     [self.navigationController pushViewController:childController animated:YES];
   163 }
   151 }
   164 
   152 
   165 /*
       
   166 -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
       
   167     UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Hey, do you see the disclosure button?" 
       
   168                                                     message:@"If you're trying to drill down, touch that instead" 
       
   169                                                    delegate:nil
       
   170                                           cancelButtonTitle:@"Won't happen again"
       
   171                                           otherButtonTitles:nil];
       
   172     [alert show];
       
   173     [alert release];
       
   174 }
       
   175 */
       
   176 
   153 
   177 #pragma mark -
   154 #pragma mark -
   178 #pragma mark Memory management
   155 #pragma mark Memory management
   179 -(void) didReceiveMemoryWarning {
   156 -(void) didReceiveMemoryWarning {
   180     // Releases the view if it doesn't have a superview.
   157     // Releases the view if it doesn't have a superview.
   181     [super didReceiveMemoryWarning];
   158     [super didReceiveMemoryWarning];
   182     
       
   183     // Relinquish ownership any cached data, images, etc that aren't in use.
   159     // Relinquish ownership any cached data, images, etc that aren't in use.
   184 }
   160 }
   185 
   161 
   186 -(void) viewDidUnload {
   162 -(void) viewDidUnload {
   187     self.listOfTeams = nil;
   163     self.listOfTeams = nil;
       
   164     childController = nil;
       
   165     [super viewDidUnload];
   188 }
   166 }
   189 
   167 
   190 -(void) dealloc {
   168 -(void) dealloc {
   191     [listOfTeams release];
   169     [listOfTeams release];
   192     [childController release];
   170     [childController release];