project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m
branchhedgeroid
changeset 6224 42b256eca362
parent 6103 55ecfbf834e3
child 6700 e04da46ee43c
equal deleted inserted replaced
6055:88cfcd9161d3 6224:42b256eca362
    39                                                                    style:UIBarButtonItemStyleBordered
    39                                                                    style:UIBarButtonItemStyleBordered
    40                                                                   target:self
    40                                                                   target:self
    41                                                                   action:@selector(toggleEdit:)];
    41                                                                   action:@selector(toggleEdit:)];
    42     self.navigationItem.rightBarButtonItem = editButton;
    42     self.navigationItem.rightBarButtonItem = editButton;
    43     [editButton release];
    43     [editButton release];
       
    44 
       
    45     self.navigationItem.title = @"List of schemes";
    44 }
    46 }
    45 
    47 
    46 -(void) viewWillAppear:(BOOL) animated {
    48 -(void) viewWillAppear:(BOOL) animated {
    47     [super viewWillAppear:animated];
    49     [super viewWillAppear:animated];
    48 
    50 
    76 }
    78 }
    77 
    79 
    78 -(void) addScheme:(id) sender {
    80 -(void) addScheme:(id) sender {
    79     NSString *fileName = [[NSString alloc] initWithFormat:@"Scheme %u.plist", [self.listOfSchemes count]];
    81     NSString *fileName = [[NSString alloc] initWithFormat:@"Scheme %u.plist", [self.listOfSchemes count]];
    80 
    82 
    81     createSchemeNamed([fileName stringByDeletingPathExtension], 0);
    83     [CreationChamber createSchemeNamed:[fileName stringByDeletingPathExtension]];
    82 
    84 
    83     [self.listOfSchemes addObject:fileName];
    85     [self.listOfSchemes addObject:fileName];
    84 
    86 
    85     // order the array alphabetically, so schemes will keep their position
    87     // order the array alphabetically, so schemes will keep their position
    86     [self.listOfSchemes sortUsingSelector:@selector(compare:)];
    88     [self.listOfSchemes sortUsingSelector:@selector(compare:)];
   124     NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),[self.listOfSchemes objectAtIndex:row]];
   126     NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),[self.listOfSchemes objectAtIndex:row]];
   125     [[NSFileManager defaultManager] removeItemAtPath:schemeFile error:NULL];
   127     [[NSFileManager defaultManager] removeItemAtPath:schemeFile error:NULL];
   126     [schemeFile release];
   128     [schemeFile release];
   127 
   129 
   128     [self.listOfSchemes removeObjectAtIndex:row];
   130     [self.listOfSchemes removeObjectAtIndex:row];
   129     [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
   131     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
   130 }
   132 }
   131 
   133 
   132 #pragma mark -
   134 #pragma mark -
   133 #pragma mark Table view delegate
   135 #pragma mark Table view delegate
   134 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   136 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   142     // this must be set so childController can load the correct plist
   144     // this must be set so childController can load the correct plist
   143     childController.schemeName = [selectedSchemeFile stringByDeletingPathExtension];
   145     childController.schemeName = [selectedSchemeFile stringByDeletingPathExtension];
   144     [childController.tableView setContentOffset:CGPointMake(0,0) animated:NO];
   146     [childController.tableView setContentOffset:CGPointMake(0,0) animated:NO];
   145 
   147 
   146     [self.navigationController pushViewController:childController animated:YES];
   148     [self.navigationController pushViewController:childController animated:YES];
       
   149     [tableView deselectRowAtIndexPath:indexPath animated:YES];
   147 }
   150 }
   148 
   151 
   149 
   152 
   150 #pragma mark -
   153 #pragma mark -
   151 #pragma mark Memory management
   154 #pragma mark Memory management