espagram/Espagram/EspagramMainTableViewController.m

159 lines
5.2 KiB
Objective-C

//
// EspagramMainTableViewController.m
// Espagram
//
// Created by Abel Fokkinga on 11/9/12.
// Copyright (c) 2012 Abel Fokkinga. All rights reserved.
//
#import "EspagramMainTableViewController.h"
#import "SpanishConjugator.h"
#import "EspagramTestViewController.h"
@interface EspagramMainTableViewController ()
@property (nonatomic, strong) NSString *language, *displayTitle;
@property (nonatomic, strong) Tense * tense;
@end
@implementation EspagramMainTableViewController
@synthesize language = _language;
@synthesize tense = _tense;
@synthesize displayTitle = _displayTitle;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (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;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
# pragma mark - Espagram setters and getters
- (id <Conjugator>) getLanguage {
if ( [@"Spanish" isEqualToString:_language] ) {
return [[SpanishConjugator alloc] init];
} else return nil;
}
- (Tense *) tense {
if ( _tense == nil ) _tense =[[Tense alloc] init];
return _tense;
}
- (void) testVerbsWithLanguage:(NSString *)language andTense:(NSString *)tense;
{
self.language = language;
self.tense = [[Tense alloc] init];
self.tense.tense = tense;
self.displayTitle = [self.tense getTenseInLanguage:@"Spanish"];
[self performSegueWithIdentifier:@"Testing" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ( [segue.identifier isEqualToString:@"Testing"]) {
EspagramTestViewController * dest = segue.destinationViewController;
dest.title = self.displayTitle;
dest.conjugator= [self getLanguage];
dest.tense =self.tense;
}
}
#pragma mark - Table view data source
/*
// 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
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * selectedTense = [tableView cellForRowAtIndexPath:indexPath].textLabel.text;
NSLog(@"Selected tense: %@", selectedTense);
if ( [selectedTense isEqualToString:@"Presente de indicativo"] ) {
[self testVerbsWithLanguage: @"Spanish" andTense:@"SIMPLE_PRESENT"];
} else if ( [selectedTense isEqualToString:@"Indefinido"] ) {
[self testVerbsWithLanguage: @"Spanish" andTense:@"SIMPLE_PAST"];
} else if ( [selectedTense isEqualToString:@"Imperfecto"] ) {
[self testVerbsWithLanguage: @"Spanish" andTense:@"IMPERFECT"];
} else if ( [selectedTense isEqualToString:@"Futuro"] ) {
[self testVerbsWithLanguage: @"Spanish" andTense:@"FUTURE"];
} else if ( [selectedTense isEqualToString:@"Pretérito Perfecto"] ) {
[self testVerbsWithLanguage: @"Spanish" andTense:@"PRESENT_PERFECT"];
} else if ( [selectedTense isEqualToString:@"Pluscuamperfecto"] ) {
[self testVerbsWithLanguage: @"Spanish" andTense:@"PAST_PERFECT"];
} else if ( [selectedTense isEqualToString:@"Futuro Perfecto"] ) {
[self testVerbsWithLanguage: @"Spanish" andTense:@"FUTURE_PERFECT"];
} else if ( [selectedTense isEqualToString:@"Condicional"] ) {
[self testVerbsWithLanguage: @"Spanish" andTense:@"CONDITIONAL"];
} else if ( [selectedTense isEqualToString:@"Condicional Perfect"] ) {
[self testVerbsWithLanguage: @"Spanish" andTense:@"CONDITIONAL_PERFECT"];
} else if ( [selectedTense isEqualToString:@"Gerundio"] ) {
[self testVerbsWithLanguage: @"Spanish" andTense:@"GERUND"];
}
}
@end