Version 0.1. Conjugation kinda working from the testing screen

This commit is contained in:
Abel Fokkinga
2012-11-09 19:39:17 +01:00
parent 0b783c1173
commit af0959ff7b
20 changed files with 1023 additions and 394 deletions

View File

@@ -0,0 +1,118 @@
//
// EspagramConjugationTableViewController.m
// Espagram
//
// Created by Abel Fokkinga on 11/9/12.
// Copyright (c) 2012 Abel Fokkinga. All rights reserved.
//
#import "EspagramConjugationTableViewController.h"
#import "Conjugator.h"
@interface EspagramConjugationTableViewController ()
@end
@implementation EspagramConjugationTableViewController
@synthesize dataSource = _dataSource;
- (void) dataSource:(id <EspagramConjugationTableView>) dataSource {
_dataSource = dataSource;
[self reloadData];
}
- (IBAction)verbEntered:(id)sender {
[self.view resignFirstResponder];
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void) reloadData {
if (_dataSource) {
NSLog(@"language %@", [self.dataSource.conjugator description]);
NSLog(@"persons %d", self.dataSource.conjugator.persons.count);
[self.tableView reloadData];
} else NSLog(@"Datasource is nil");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [[[self.dataSource conjugator] persons] count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *sectionName;
switch (section)
{
case 0:
sectionName = self.dataSource.verb;
break;
default:
sectionName = @"";
break;
}
return sectionName;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ConjugatedVerbPerson";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString * person = [[self.dataSource.conjugator personsKeys] objectAtIndex:indexPath.row];
cell.textLabel.text = [self.dataSource.conjugator.persons objectForKey:person];
cell.detailTextLabel.text = [self.dataSource.conjugator conjugateVerb:self.dataSource.verb inPerson:person andTense:self.dataSource.tense];
return cell;
}
- (void)viewDidLoad
{
[self.tableView reloadData];
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
@end