--- a/project_files/HedgewarsMobile/Classes/CampaignViewController.m Tue Feb 23 13:45:49 2016 +0300
+++ b/project_files/HedgewarsMobile/Classes/CampaignViewController.m Tue Feb 23 23:29:06 2016 +0100
@@ -17,13 +17,35 @@
*/
#import "CampaignViewController.h"
+#import "IniParser.h"
@interface CampaignViewController ()
-
+@property (nonatomic, retain) NSArray *campaignMissions;
@end
@implementation CampaignViewController
+#pragma mark - Lazy instantiation
+
+- (NSArray *)campaignMissions {
+ if (!_campaignMissions) {
+ _campaignMissions = [self newParsedMissionsForCurrentCampaign];
+ }
+ return _campaignMissions;
+}
+
+- (NSArray *)newParsedMissionsForCurrentCampaign {
+ NSString *campaignIniPath = [CAMPAIGNS_DIRECTORY() stringByAppendingFormat:@"%@/campaign.ini", self.campaignName];
+
+ IniParser *iniParser = [[IniParser alloc] initWithIniFilePath:campaignIniPath];
+ NSArray *parsedMissions = [iniParser newParsedSections];
+ [iniParser release];
+
+ return parsedMissions;
+}
+
+#pragma mark - View lifecycle
+
- (void)viewDidLoad {
[super viewDidLoad];
@@ -31,8 +53,7 @@
self.navigationItem.rightBarButtonItem = doneButton;
[doneButton release];
- NSString *campaignIniPath = [CAMPAIGNS_DIRECTORY() stringByAppendingFormat:@"%@/campaign.ini", self.campaignName];
- NSLog(@"%@", campaignIniPath);
+ [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"campaignMissionCell"];
}
- (void)dismiss {
@@ -47,58 +68,21 @@
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
-#warning Incomplete implementation, return the number of sections
- return 0;
+ return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-#warning Incomplete implementation, return the number of rows
- return 0;
+ return [self.campaignMissions count];
}
-/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"campaignMissionCell" forIndexPath:indexPath];
// Configure the cell...
+ cell.textLabel.text = self.campaignMissions[indexPath.row][@"Name"];
return cell;
}
-*/
-
-/*
-// Override to support conditional editing of the table view.
-- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- // Return NO if you do not want the specified item to be editable.
- return YES;
-}
-*/
-
-/*
-// Override to support editing the table view.
-- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- if (editingStyle == UITableViewCellEditingStyleDelete) {
- // Delete the row from the data source
- [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
- } else if (editingStyle == UITableViewCellEditingStyleInsert) {
- // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
- }
-}
-*/
-
-/*
-// Override to support rearranging the table view.
-- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
-}
-*/
-
-/*
-// Override to support conditional rearranging of the table view.
-- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
- // Return NO if you do not want the item to be re-orderable.
- return YES;
-}
-*/
/*
#pragma mark - Table view delegate
@@ -116,18 +100,11 @@
}
*/
-/*
-#pragma mark - Navigation
-
-// In a storyboard-based application, you will often want to do a little preparation before navigation
-- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
-}
-*/
+#pragma mark - Dealloc
- (void)dealloc {
[_campaignName release];
+ [_campaignMissions release];
[super dealloc];
}