FMCPlanner2/FMC Planner 2/TableViewController.m

107 lines
3.5 KiB
Objective-C

//
// TableViewController.m
// FMC Planner 2
//
// Created by Kilian Hofmann on 27.03.16.
// Copyright © 2016 Kilian Hofmann. All rights reserved.
//
#import "TableViewController.h"
@implementation TableViewController
#pragma mark - View management and navigation
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation
// bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
if ([self.title isEqualToString:@"Manage"]) {
NSArray *temp = [[NSFileManager defaultManager]
contentsOfDirectoryAtPath:[SharedDeclerations savePathForFile:@""]
error:nil];
_dataSource = [[temp
filteredArrayUsingPredicate:
[NSPredicate predicateWithFormat:@"NOT (SELF BEGINSWITH %@)",
@"."]] mutableCopy];
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return _dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:@"Cell"
forIndexPath:indexPath];
if ([self.title isEqualToString:@"Manage"]) {
NSDictionary *data = [[NSDictionary alloc]
initWithContentsOfFile:[SharedDeclerations
savePathForFile:_dataSource[indexPath
.row]]];
cell.textLabel.text = [data valueForKey:@"MENU@LSKR1"];
}
return cell;
}
#pragma mark - Table view editing action
// 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
[[NSFileManager defaultManager]
removeItemAtPath:[SharedDeclerations
savePathForFile:_dataSource[indexPath.row]]
error:nil];
[_dataSource removeObjectAtIndex:indexPath.row];
[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
}
}
#pragma mark - Table view cell selection action
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.title isEqualToString:@"Manage"]) {
[self dismissViewControllerAnimated:YES
completion:^(void) {
[_main loadSave:[tableView
cellForRowAtIndexPath:
indexPath]
.textLabel.text];
}];
}
}
@end