cocoaTouch/TeamSettingsViewController.m
changeset 3479 972ae3ec178a
parent 3373 c1ff724a5c34
child 3490 016b3172b645
equal deleted inserted replaced
3478:cbf71e938164 3479:972ae3ec178a
    23 #pragma mark View lifecycle
    23 #pragma mark View lifecycle
    24 // add an edit button
    24 // add an edit button
    25 -(void) viewDidLoad {
    25 -(void) viewDidLoad {
    26     [super viewDidLoad];
    26     [super viewDidLoad];
    27 
    27 
    28     UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Edit",@"from the team navigation")
    28     UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Edit",@"from the team panel")
    29                                                                    style:UIBarButtonItemStyleBordered
    29                                                                    style:UIBarButtonItemStyleBordered
    30                                                                   target:self
    30                                                                   target:self
    31                                                                   action:@selector(toggleEdit:)];
    31                                                                   action:@selector(toggleEdit:)];
    32     self.navigationItem.rightBarButtonItem = editButton;
    32     self.navigationItem.rightBarButtonItem = editButton;
    33     [editButton release];
    33     [editButton release];
    49 -(void) toggleEdit:(id) sender {
    49 -(void) toggleEdit:(id) sender {
    50     BOOL isEditing = self.tableView.editing;
    50     BOOL isEditing = self.tableView.editing;
    51     [self.tableView setEditing:!isEditing animated:YES];
    51     [self.tableView setEditing:!isEditing animated:YES];
    52     
    52     
    53     if (isEditing) {
    53     if (isEditing) {
    54         [self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Edit",@"from the team navigation")];
    54         [self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Edit",@"from the team panel")];
    55         [self.navigationItem.rightBarButtonItem setStyle: UIBarButtonItemStyleBordered];
    55         [self.navigationItem.rightBarButtonItem setStyle: UIBarButtonItemStyleBordered];
    56         self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem;
    56         self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem;
    57     } else {
    57     } else {
    58         [self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Done",@"from the team navigation")];
    58         [self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Done",@"from the team panel")];
    59         [self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
    59         [self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
    60         UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Add",@"from the team navigation")
    60         UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Add",@"from the team panel")
    61                                                                       style:UIBarButtonItemStyleBordered
    61                                                                       style:UIBarButtonItemStyleBordered
    62                                                                      target:self
    62                                                                      target:self
    63                                                                      action:@selector(addTeam:)];
    63                                                                      action:@selector(addTeam:)];
    64         self.navigationItem.leftBarButtonItem = addButton;
    64         self.navigationItem.leftBarButtonItem = addButton;
    65         [addButton release];
    65         [addButton release];
    86 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    86 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    87     return 1;
    87     return 1;
    88 }
    88 }
    89 
    89 
    90 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    90 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    91     return [listOfTeams count];
    91     return [self.listOfTeams count];
    92 }
    92 }
    93 
    93 
    94 // Customize the appearance of table view cells.
    94 // Customize the appearance of table view cells.
    95 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    95 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    96     static NSString *CellIdentifier = @"Cell";
    96     static NSString *CellIdentifier = @"Cell";
    99     if (cell == nil) {
    99     if (cell == nil) {
   100         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
   100         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
   101     }
   101     }
   102     
   102     
   103     NSUInteger row = [indexPath row]; 
   103     NSUInteger row = [indexPath row]; 
   104     NSString *rowString = [[listOfTeams objectAtIndex:row] stringByDeletingPathExtension]; 
   104     NSString *rowString = [[self.listOfTeams objectAtIndex:row] stringByDeletingPathExtension]; 
   105     cell.textLabel.text = rowString; 
   105     cell.textLabel.text = rowString; 
   106     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
   106     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
   107     
   107     
   108     return cell;
   108     return cell;
   109 }
   109 }
   118     
   118     
   119     [self.listOfTeams removeObjectAtIndex:row];
   119     [self.listOfTeams removeObjectAtIndex:row];
   120     [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
   120     [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
   121 }
   121 }
   122 
   122 
   123 /*
       
   124 // Override to support editing the table view.
       
   125 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
       
   126     
       
   127     if (editingStyle == UITableViewCellEditingStyleDelete) {
       
   128         // Delete the row from the data source
       
   129         [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
       
   130     }   
       
   131     else if (editingStyle == UITableViewCellEditingStyleInsert) {
       
   132         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
       
   133     }   
       
   134 }
       
   135 */
       
   136 
       
   137 
   123 
   138 #pragma mark -
   124 #pragma mark -
   139 #pragma mark Table view delegate
   125 #pragma mark Table view delegate
   140 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   126 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   141     if (childController == nil) {
   127     if (childController == nil) {
   142         childController = [[SingleTeamViewController alloc] initWithStyle:UITableViewStyleGrouped];
   128         childController = [[SingleTeamViewController alloc] initWithStyle:UITableViewStyleGrouped];
   143     }
   129     }
   144     
   130     
   145     NSInteger row = [indexPath row];
   131     NSInteger row = [indexPath row];
   146     NSString *selectedTeamFile = [listOfTeams objectAtIndex:row];
   132     NSString *selectedTeamFile = [listOfTeams objectAtIndex:row];
   147     NSLog(@"%@",selectedTeamFile);
       
   148     
   133     
   149     // this must be set so childController can load the correct plist
   134     // this must be set so childController can load the correct plist
   150     childController.title = [selectedTeamFile stringByDeletingPathExtension];
   135     childController.title = [selectedTeamFile stringByDeletingPathExtension];
   151     [childController.tableView setContentOffset:CGPointMake(0,0) animated:NO];
   136     [childController.tableView setContentOffset:CGPointMake(0,0) animated:NO];
   152 
   137 
   167     childController = nil;
   152     childController = nil;
   168     [super viewDidUnload];
   153     [super viewDidUnload];
   169 }
   154 }
   170 
   155 
   171 -(void) dealloc {
   156 -(void) dealloc {
   172     [listOfTeams release];
   157     [self.listOfTeams release];
   173     [childController release];
   158     [childController release];
   174     [super dealloc];
   159     [super dealloc];
   175 }
   160 }
   176 
   161 
   177 
   162