project_files/HedgewarsMobile/Classes/CampaignsViewController.m
changeset 11560 664d3592a66b
parent 11559 2b9e189df3d6
child 11562 32bbf1f6bb2b
equal deleted inserted replaced
11559:2b9e189df3d6 11560:664d3592a66b
    17  */
    17  */
    18 
    18 
    19 #import "CampaignsViewController.h"
    19 #import "CampaignsViewController.h"
    20 
    20 
    21 @interface CampaignsViewController ()
    21 @interface CampaignsViewController ()
    22 
    22 @property (nonatomic, retain) NSArray *campaigns;
    23 @end
    23 @end
    24 
    24 
    25 @implementation CampaignsViewController
    25 @implementation CampaignsViewController
       
    26 
       
    27 #pragma mark - Lazy instantiation
       
    28 
       
    29 - (NSArray *)campaigns {
       
    30     if (!_campaigns) {
       
    31         _campaigns = [self listOfCampaigns];
       
    32     }
       
    33     return _campaigns;
       
    34 }
       
    35 
       
    36 - (NSArray *)listOfCampaigns {
       
    37     NSFileManager *fileManager = [NSFileManager defaultManager];
       
    38     NSArray *contents = [fileManager contentsOfDirectoryAtPath:CAMPAIGNS_DIRECTORY() error:nil];
       
    39     
       
    40     NSMutableArray *tempCampaigns = [[NSMutableArray alloc] init];
       
    41     for (NSString *item in contents) {
       
    42         NSString *fullItemPath = [CAMPAIGNS_DIRECTORY() stringByAppendingString:item];
       
    43         BOOL isDirectory;
       
    44         if ([fileManager fileExistsAtPath:fullItemPath isDirectory:&isDirectory] && isDirectory) {
       
    45             [tempCampaigns addObject:item];
       
    46         }
       
    47     }
       
    48     
       
    49     NSArray *campaigns = [tempCampaigns copy];
       
    50     [tempCampaigns release];
       
    51     return campaigns;
       
    52 }
       
    53 
       
    54 #pragma mark - View lifecycle
    26 
    55 
    27 - (void)viewDidLoad {
    56 - (void)viewDidLoad {
    28     [super viewDidLoad];
    57     [super viewDidLoad];
    29     
    58     
    30     UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismiss)];
    59     UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismiss)];
    31     self.navigationItem.leftBarButtonItem = doneButton;
    60     self.navigationItem.leftBarButtonItem = doneButton;
    32     [doneButton release];
    61     [doneButton release];
       
    62     
       
    63     [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"campaignCell"];
    33 }
    64 }
    34 
    65 
    35 - (void)dismiss {
    66 - (void)dismiss {
    36     [self.navigationController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
    67     [self.navigationController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
    37 }
    68 }
    42 }
    73 }
    43 
    74 
    44 #pragma mark - Table view data source
    75 #pragma mark - Table view data source
    45 
    76 
    46 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    77 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    47 #warning Incomplete implementation, return the number of sections
    78     return 1;
    48     return 0;
       
    49 }
    79 }
    50 
    80 
    51 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    81 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    52 #warning Incomplete implementation, return the number of rows
    82     return [self.campaigns count];
    53     return 0;
       
    54 }
    83 }
    55 
    84 
    56 /*
       
    57 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    85 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    58     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    86     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"campaignCell" forIndexPath:indexPath];
    59     
    87     
    60     // Configure the cell...
    88     cell.textLabel.text = self.campaigns[indexPath.row];
    61     
    89     
    62     return cell;
    90     return cell;
    63 }
    91 }
    64 */
       
    65 
       
    66 /*
       
    67 // Override to support conditional editing of the table view.
       
    68 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
       
    69     // Return NO if you do not want the specified item to be editable.
       
    70     return YES;
       
    71 }
       
    72 */
       
    73 
       
    74 /*
       
    75 // Override to support editing the table view.
       
    76 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
       
    77     if (editingStyle == UITableViewCellEditingStyleDelete) {
       
    78         // Delete the row from the data source
       
    79         [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
       
    80     } else if (editingStyle == UITableViewCellEditingStyleInsert) {
       
    81         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
       
    82     }   
       
    83 }
       
    84 */
       
    85 
       
    86 /*
       
    87 // Override to support rearranging the table view.
       
    88 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
       
    89 }
       
    90 */
       
    91 
       
    92 /*
       
    93 // Override to support conditional rearranging of the table view.
       
    94 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
       
    95     // Return NO if you do not want the item to be re-orderable.
       
    96     return YES;
       
    97 }
       
    98 */
       
    99 
    92 
   100 /*
    93 /*
   101 #pragma mark - Table view delegate
    94 #pragma mark - Table view delegate
   102 
    95 
   103 // In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
    96 // In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
   111     // Push the view controller.
   104     // Push the view controller.
   112     [self.navigationController pushViewController:detailViewController animated:YES];
   105     [self.navigationController pushViewController:detailViewController animated:YES];
   113 }
   106 }
   114 */
   107 */
   115 
   108 
   116 /*
   109 #pragma mark - Dealloc
   117 #pragma mark - Navigation
       
   118 
   110 
   119 // In a storyboard-based application, you will often want to do a little preparation before navigation
   111 - (void)dealloc {
   120 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
   112     [_campaigns release];
   121     // Get the new view controller using [segue destinationViewController].
   113     [super dealloc];
   122     // Pass the selected object to the new view controller.
       
   123 }
   114 }
   124 */
       
   125 
   115 
   126 @end
   116 @end